-
-
Save zhangwc/6445656 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aBook = [[Book alloc] initWithBookNO:@"NO.21342413" bookName:@"清朝秘史" author:@"张家州" price:25.50]; | |
[aBook addObserver:self forKeyPath:@"price" options:NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew context:nil]; | |
// 观察到变化(收到来自被观察者的消息通知) | |
- (void)observeValueForKeyPath:(NSString *)keyPath | |
ofObject:(id)object | |
change:(NSDictionary *)change | |
context:(void *)context | |
{ | |
if([keyPath isEqual:@"price"]) { | |
NSLog(@">>>>>>>price is changed"); | |
NSLog(@"old price is %@",[change objectForKey:@"old"]); | |
NSLog(@"new price is %@",[change objectForKey:@"new"]); | |
} | |
} | |
[aBook removeObserver:self forKeyPath:@"price"]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment