Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About listing the observers for a specific object

  1. Is there a way to know which is the list of observers for a specific instance ?

  2. How am I suppose to use observationInfo, could you provide an example ?

thanks

like image 393
aneuryzm Avatar asked Mar 30 '12 10:03

aneuryzm


1 Answers

There is a write-up of how to use observationInfo in "Technical Note TN2124: Mac OS X Debugging Magic." The idea is that you can use it in the debugger to discover the information you need.

Not only that, but I tried using it like this:

id what = [self observationInfo];
NSLog(@"%@", [what description]);

and this is what I got in the log:

    <NSKeyValueObservationInfo 0x7fdb8953c380> (
<NSKeyValueObservance 0x7fdb8953c270: Observer: 0x7fdb8953bf60, Key path: subscribed, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x7fdb8953c350>
)

('subscribed' is an ivar in one of my own objects)

There doesn't appear to be a public interface either for NSKeyValueObservationInfo or NSKeyValueObservance.

It appears I got the benefit of learning something new from your question!

like image 95
Extra Savoir-Faire Avatar answered Jan 01 '23 09:01

Extra Savoir-Faire