|
| 1 | +protocol Observed: AnyObject { |
| 2 | +} |
| 3 | + |
| 4 | +struct Other<Value: Equatable> { |
| 5 | + var value: Value |
| 6 | + |
| 7 | + func hello() -> String { |
| 8 | + return "Hello from \(value)" |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +@propertyWrapper |
| 13 | +struct Observable<Value: Equatable> { |
| 14 | + private var stored: Value |
| 15 | + |
| 16 | + |
| 17 | + init(wrappedValue: Value) { |
| 18 | + self.stored = wrappedValue |
| 19 | + } |
| 20 | + |
| 21 | + var wrappedValue: Value { |
| 22 | + get { fatalError("called wrappedValue getter") } |
| 23 | + set { fatalError("called wrappedValue setter") } |
| 24 | + } |
| 25 | + |
| 26 | + var projectedValue: Other<Value> { |
| 27 | + get { fatalError("called projectedValue getter") } |
| 28 | + set { fatalError("called projectedValue setter") } |
| 29 | + } |
| 30 | + |
| 31 | + static subscript<EnclosingSelf: Observed, FinalValue>( |
| 32 | + _enclosingInstance observed: EnclosingSelf, |
| 33 | + wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, FinalValue>, |
| 34 | + storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self> |
| 35 | + ) -> Value { |
| 36 | + get { |
| 37 | + fatalError("blah") |
| 38 | + } |
| 39 | + set { |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + static subscript<EnclosingSelf: Observed>( |
| 44 | + _enclosingInstance observed: EnclosingSelf, |
| 45 | + projected wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Other<Value>>, |
| 46 | + storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self> |
| 47 | + ) -> Other<Value> { |
| 48 | + get { |
| 49 | + fatalError("blah") |
| 50 | + } |
| 51 | + set { |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments