美文网首页
iOS 关于KVC

iOS 关于KVC

作者: 心情的颜色 | 来源:发表于2015-09-09 10:04 被阅读57次

  KVC( Key - Value - Coding ),键值编码,是一种间接访问实例变量的方法

 Key : 键,用于标识实例变量

 Value : 实例变量对应的值.

 注意: 当 key 不存在的时候, 会执行 setValue:  forVndefinedKey:

类中有 @private 私有实力变量时可以用 KVC 操作

 KVC 最常用的还是在序列化和反序列话对象。我们经常需要把json字符串反序列化成我们想要的对象

#import#import "Father.h"

#import "Book.h"

@interface Person : NSObject {

@public

NSString *_fullName;

@private

NSString *_name;

Father *_father;

NSArray *_books;

}

@end

  Person *person = [[Person alloc] init]; 

KVC 赋值

 [person setValue:@"张三" forKey:@"_name"];

相关文章

网友评论

      本文标题:iOS 关于KVC

      本文链接:https://www.haomeiwen.com/subject/zycpcttx.html