监听一个model值得变化
[self.model addObserver:self forKeyPath:@"note" options:NSKeyValueObservingOptionNew context:nil];
重写方法ObserveValueForkeypath方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
NSLog(@"keyPath %@",keyPath);
NSLog(@"被修改的对象 %@",object);
NSLog(@"被修改的值 %@",[change objectForKey:@"new"]);
NSLog(@"被修改的上下文 %@",context);
}
移除
-(void)dealloc{
[self.model removeObserver:self forKeyPath:@"note"];
}