jens@0: // jens@0: // KVUtils.h jens@0: // MYUtilities jens@0: // jens@0: // Created by Jens Alfke on 2/25/08. jens@0: // Copyright 2008 Jens Alfke. All rights reserved. jens@0: // jens@0: jens@0: #import jens@0: jens@0: jens@0: enum { jens@0: MYKeyValueObservingOptionOnce = 1<<31, jens@0: MYKeyValueObservingOptionDelayed = 1<<30 jens@0: }; jens@0: jens@0: jens@0: jens@0: @interface Observance : NSObject jens@0: { jens@0: id _target; jens@0: id _observed; jens@0: NSString *_keyPath; jens@0: NSKeyValueObservingOptions _options; jens@0: SEL _action; jens@0: } jens@0: jens@0: - (id) initWithTarget: (id)target jens@0: action: (SEL)action jens@0: observed: (id)observed jens@0: keyPath: (NSString*)keyPath jens@0: options: (NSKeyValueObservingOptions)options; jens@0: jens@0: - (void) stopObserving; jens@0: jens@0: @property (readonly) id observed; jens@0: @property (readonly) NSString* keyPath; jens@0: jens@0: @end jens@0: jens@0: jens@0: jens@0: @interface Observer : NSObject jens@0: { jens@0: id _target; jens@0: NSMutableArray *_observances; jens@0: } jens@0: jens@0: - (id) initWithTarget: (id)target; jens@0: jens@0: @property (readonly) id target; jens@0: jens@0: - (void) observe: (id)observed jens@0: keyPath: (NSString*)keyPath jens@0: options: (NSKeyValueObservingOptions)options jens@0: action: (SEL)action; jens@0: jens@0: - (void) observe: (id)observed jens@0: keyPath: (NSString*)keyPath jens@0: action: (SEL)action; jens@0: jens@3: /** observed or keyPath may be nil, meaning wildcard */ jens@0: - (void) stopObserving: (id)observedOrNil keyPath: (NSString*)keyPathOrNil; jens@3: - (void) stopObserving: (id)observed; jens@0: - (void) stopObserving; jens@0: jens@0: @end