我的 NSMutableDictionary 包含简单的键(@"one"、@"two"、@"three")和复杂的键(@"com.alpha"、@"com.beta")。是否可以将观察者用于复杂键?
观察者可以很好地使用简单的键,但不能使用复杂的键。什么是解决方案?
[self.dict addObserver:self forKeyPath:@"com.alpha" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
-(IBAction) onChange:(id)sender
{
[self.dict setObject:@"newValue" forKey:@"com.alpha"];
}
-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"____ value had changed");
}