开发者

how to see what an object is observing in cocoa

开发者 https://www.devze.com 2023-03-08 15:58 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消