swift - KVO - change.newValue and change.oldValue are nil

Viewed 1633

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:

enter image description here

1 Answers
Related