Wednesday, September 24, 2008

KVO Issue With Subclassing

Tim Wood:

The core of the problem is an API flaw in KVO; -removeObserver:forKeyPath: doesn’t include a context argument. So, if you have an object that is subscribed to a key twice, with two different context pointers, it is undefined which will get removed. If your object is dying and cleaning up all observations, this isn’t a big deal. But if your subclass logic wants to temporarily turn off its observation, it has no way to make sure that’s what happens—it might instead end up removing the superclass observation.

Comments RSS · Twitter

Leave a Comment