Skip to content

Instantly share code, notes, and snippets.

@tolmasky
Created July 12, 2011 20:56
Show Gist options
  • Select an option

  • Save tolmasky/1078964 to your computer and use it in GitHub Desktop.

Select an option

Save tolmasky/1078964 to your computer and use it in GitHub Desktop.
@interface _KeyPathObserver : NSObject
@end
@implementation NSObject (Additions)
- (void)performSelector:(SEL)aSelector forChangesInKeyPath:(NSString *)aKeyPath
{
[self addObserver:(id)[_KeyPathObserver class] forKeyPath:aKeyPath options:NSKeyValueObservingOptionNew context:aSelector];
}
@end
@implementation _KeyPathObserver
+ (void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject change:(NSDictionary *)aChange context:(void *)aContext
{
[anObject performSelector:(SEL)aContext];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment