-
Notifications
You must be signed in to change notification settings - Fork 3
/
PARObjectObserver.h
33 lines (26 loc) · 1.23 KB
/
PARObjectObserver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// PARViewController
// Author: Charles Parnot
// Licensed under the terms of the BSD License, as specified in the file 'LICENSE-BSD.txt' included with this distribution
@interface PARObjectObserver : NSObject
{
__unsafe_unretained id observedObject;
__unsafe_unretained id delegate;
SEL callbackSelector;
NSArray *observedKeys;
BOOL callbackMainThreadOnly;
}
@property (readonly, assign) id observedObject;
@property (readonly, retain) NSArray *observedKeys;
+ (PARObjectObserver *)observerWithDelegate:(id)delegate selector:(SEL)callbackSelector observedKeys:(NSArray *)observedKeys observedObject:(id)observedObject;
// in GC environments, call this method when the observer is no longer needed (but not in the `finalize` method)
// in non-GC, you can still call it, but it's also automatically done in dealloc
- (void)invalidate;
// forces callback on main thread -- default = YES
@property BOOL callbackMainThreadOnly;
@end
// callback methods can use any of the following signatures (0, 1 or 2 arguments), but can otherwise use any name
@interface NSObject (PARObjectObserverDelegate)
- (void)valueDidChange;
- (void)valueDidChangeForKey:(NSString *)key;
- (void)valueDidChangeForKey:(NSString *)key observedObject:(id)observedObject;
@end