Conditional projected property?

Is this supported? I can't test it with the latest Xcode snapshot, it crashes on me.

@propertyWrapper
struct Wrapper<Value> {
  var wrappedValue: Value
}

extension Wrapper where Value == Int {
  var projectedValue: String {
    return "\(wrappedValue)"
  }
}

struct S {
  @Wrapper var a = "swift"
  @Wrapper var b = 42
  
  func foo() {
//    print(self.$a)
    print(self.$b)
  }
}

let s = S()
s.foo()

cc @Douglas_Gregor

If this is not supported, but should, let me know I'll file a ticket.

@Douglas_Gregor I filed a bug report https://bugs.swift.org/browse/SR-11209. I have an important use case where I need this feature to work.

Terms of Service

Privacy Policy

Cookie Policy