(''')
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,copy)NSString *name;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//KVO
[self addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
//kvc
[selfsetValue:@"张雨涵"forKey:@"name"];
//点语法
self.name = @"zhangcc";
// Do any additional setup after loading the view, typically from a nib.
}
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void*)context{
NSLog(@"keyName = %@",keyPath);
NSLog(@"change = %@",change);
}
(''')
*编译结果
2019-02-21 14:04:41.742268+0800 面试题[9125:958213] keyName = name
2019-02-21 14:04:41.742626+0800 面试题[9125:958213] change = {
kind = 1;
new = "\U5f20\U96e8\U6db5";
old = "";
}
2019-02-21 14:04:41.742820+0800 面试题[9125:958213] keyName = name
2019-02-21 14:04:41.742998+0800 面试题[9125:958213] change = {
kind = 1;
new = zhangcc;
old = "\U5f20\U96e8\U6db5";
}
(''')
网友评论