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 (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com