A pretty simple question, but I can't seem to find an answer. (Developing an iOS 5+ app).
In my AppDelegate, I have a property, let's call it @property (non atomic) BOOL aFlag;
. I'd like my AppDelegate to be notified if the value changes. Here is what I tried (everything happens in the AppDelegate.m
), which is the same as when I "link" two different objects with an observer :
-(BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Some stuff
_aFlag = YES;
[self addObserver:self
forKeyPath:@"aFlag"
options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context:nil];
// Some other stuff
}
-(void)observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context {
if ([keyPath isEqual:@"aFlag"]) {
// Do something
} else {
// Do nothing
}
}
But observeValueForKeyPath:
is not called.
Where am I wrong ? Thanks.