// ———————————————————————KVO——————————————
// 定义对象,设置KVO
p = [[Person alloc] init];
p.name = @"zhangsan";
p.age = 22;
[p addObserver:self forKeyPath:@"age" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:NULL];
// 实现KVO监听
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([@"age" isEqualToString:keyPath])
{
NSLog(@"observeValueForKeyPath.....");
}
}
// 释放
-(void)dealloc
{
[p removeObserver:self forKeyPath:@"age"];
}