Avatar
Avatar
Iceman
@swift-6.0.3@propertyWrapper indirect enum CoW<Value> { case storage(Value) init(_ value: Value) { self = .storage(value) } var wrappedValue: Value { get { switch self { case .storage(let v): return v } } set { self = .storage(newValue) } } } struct MyStruct { var age: Int @CoW var next: MyStruct? } var aaa = MyStruct(age: 1, next: .init(.init(age: 2, next: .init(nil)))) let iii = aaa print(aaa.next?.age) print(iii.next?.age) aaa.next?.age += 100 print(aaa.next?.age) print(iii.next?.age)
Optional(2) Optional(2) Optional(102) Optional(2)<stdin>:28:7: warning: expression implicitly coerced from 'Int?' to 'Any' 26 | var aaa = MyStruct(age: 1, next: .init(.init(age: 2, next: .init(nil)))) 27 | let iii = aaa
2.01 KB