how to see what an object is observing in cocoa
I know there is a way to see what properties are being observed on an object with observationInfo but is there a way to see what an object is set to observe?
[otherObject addObserver开发者_如何学运维:zombie forKeyPath:@"brains" context:apocalypse]
Calling [otherObject observationInfo] reveals that the zombie is observing the @"brains" keypath but I would like to call [zombie observerFor] or something and see what it is set as an observer for....
I don't think you can do this. The implementation of KVO stores pointers to the observing object in the observed object (sort of, actually, it's a dynamically created subclass of the observed object). So the observing object does not maintain any reference to the objects it is observing. The Apple documentation on KVO here says a little bit more. This thread says a little bit more about the actual implementation of KVO and isa-swizzling.
精彩评论