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...

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

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

I think it would be useful too. It's going to become a common use case with Combine and SwiftUI. I hope it's coming.