I’m trying to observe changes to an NSMutableString isDetailView:
-(void)viewDidLoad {
[self addObserver:self forKeyPath:@"isDetailView" options:NSKeyValueObservingOptionNew context:nil];
[isDetailView setString:@"YES"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"obersedValueFOrKeyPath:%@", keyPath);
}
But the observeValueForKeyPath method never gets called. Any ideas?
You are not changing the property, only the content of the object it points to. If you make
isDetailViewa normal string and doit will work.
By the way, properties that start “is” are conventionally supposed to be boolean and that looks like a more appropriate type in this case too.