I'm using the new KeyValue Observing. I'm getting a call to my observer when the variable changes, but the change
struct comes with newValue
and oldValue
both as nil
, so it never gets to the //do something
part:
let observer = foo.observe(\.bar, options: [.new, .old]) { obj, change in
if change.kind == .setting && change.oldValue != change.newValue {
// do something
}
}
It used to work perfectly with the old way of doing KVO.
I made that code more simple as an example, here is a debugging of my actual code. You can see that the m
object has the status
var has been set to PREPARING
but both change.oldValue
and change.newValue
are nil:
This is a Swift bug which has been reported as https://bugs.swift.org/browse/SR-5872. A pull request which addresses this issue is being discussed on https://github.com/apple/swift/pull/20757 but is not yet merged as of March 2022.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With