kvc,key value coding,键值编码
Person *p = [[Person alloc] init];
p.name = "aaa";
// 获取值valueForKeyPath
NSString *name = [p valueForKeyPath:@"name"]; //== p.name
Person *p2 = [[Person alloc] init];
p2.name = "bbb";
NSArray *arr = @[p, p2];
NSArray *nameArray = [arr valueForKeyPath]; // 返回["aaa", "bbb"]
// 为对象赋值
[p1 setValue:@"cc" forKeyPath:@"name"]
// 把对象赋值给字典
NSDictionary *dict = [p1 dictionaryWithValuesForKeys:@[@"name"]]
// 把字典赋值给对象
[p1 setValuesForKeysWithDictionary:dic]
如果对象属性不全的情况,会抛异常,解决方法是,写一个setValue: forUndefinedKey:空方法