How to define a protocol with property wrapper?

I would like to define a protocol with property wrapper. However, $ prefix is reserved. So, I can't do it...
Heh.

protocol SomeProtocol {
  var property: String {get}
  var propertyWrapper: Published<String> {get}
  var $property: Published<String> {get}
}
1 Like

That is not possible and I‘m not sure it ever will, at least not until property wrappers will have more control over access levels. Furthermore I wouldn‘t be surprised if projected properties won‘t ever be allowed as protocol requirements.

However I could be wrong with some of these things, that‘s why @Douglas_Gregor can answer this question more precise.


You could however workaround it if you desperately need such a protocol, but you will need to link the propeties manually.

protocol SomeProtocol {
  // that will require manual linking
  var propertyWrapper: Published<String> { get set }
  var property: String { get set }

  // that will require manual linking
  var _$property: Published<String>.Publisher { get }
}

Are there any specific posts/quotes from the Core Team et al. that would indicate that? I've been trying to comb through the pitch/review threads on property wrappers to find anything backing that up to no avail.

1 Like
Terms of Service

Privacy Policy

Cookie Policy