Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
- Subject: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
- From: Richard Somers <email@hidden>
- Date: Sun, 09 Sep 2012 06:07:35 -0600
On Sep 9, 2012, at 3:32 AM, Motti Shneor wrote:
> - (NSUInteger)isObserver:(id)object on keyPath:(NSString *)keyPath withContext:(void *)context]; // the returned number is the count of same observances with 0 as not-observing).
>
> and something like
>
> - (BOOL)removeObserver:(id)object; // where I instruct the receiver to remove object as an observer, on all key-paths and contexts. should return YES if object was an observer, and was removed, NO otherwise.
>
> Any ideas?
I recently did something similar only for bindings.
@interface NSObject (MYBindings)
+ (NSString *)my_objectsWithActiveBindings; // for debugging
+ (NSUInteger)my_objectsWithActiveBindingsCount; // for debugging
- (void)my_revmoveAllBindings;
@end
This was implemented by swizzling the NSObject implementation of -bind:toObject:withKeyPath:options: and -unbind: at runtime using JRSwizzle along with keeping binding information for each instance in a single static mutable dictionary (associative storage pattern). The swizzled methods call the NSObject implementation of -bind:... and -unbind: and also keep track of the additional binding information needed.
I am working on a project with a lot of programmatic bindings and I needed some debugging aids and other routines to help with binding management. At first I was hesitant to swizzle a framework method but I desperately needed some help. So far it seems to be working well and the new routines helped uncover a bug that I literally spent days trying to find with no success.
--Richard
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden