Property wrappers are stored properties, so I expected didSet/willSet to work as usual, but they are ignored actually. Here is a short example:
@propertyWrapper
struct MutableWrapper<Value> {
var wrappedValue: Value
var projectedValue: Self {
get { self }
set { self = newValue }
}
mutating func mutate() {
// any mutations here
}
}
struct TestStruct {
@MutableWrapper var value = 0 {
didSet { print("mutated") }
}
}
func testDidSet() {
var testStruct = TestStruct()
testStruct.$value.mutate() // prints nothing
testStruct.value = 1 // prints nothing
}
All sets are mutating; I don't use classes, so it's definitely a bug. Does anybody know something about it?
I really need to observe mutations of my wrapper itself. I didn't expect any problems here, especially since the compiler allowed me to write didSet under the wrapped value.