KVC一句话搞定赋值
2015-11-19 10:22
302 查看
- (instancetype)initWithDic:(NSDictionary*)dic{ if (self = [super init]) { [self setValuesForKeysWithDictionary:dic]; } return self; }
如果没有哪个属性,自己定义的而服务器没有这个属性的! - (void)setValue:(id)value forUndefinedKey:(NSString *)key{ if ([key isEqualToString:@"comment"]) { NSInteger commentCount = [value integerValue]; _pinLun = [[NSString stringWithFormat:@"%ld",(long)commentCount] copy]; } NSLog(@"%@",value); } comment 是服务器的属性 _pinlun 是自己定义的属性
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{ NSLog(@"=------:%@",key); if ([key isEqualToString:@"description"]) { _des = value; }else if ([key isEqualToString:@"photos"]){ NSArray *photos = (NSArray*)value; NSMutableArray *appPhotoes = [NSMutableArray array]; [photos enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) { // 1.创建AppPhoto对象 AppPhoto *photo = [AppPhoto appPhotoWithDic:dic]; // 2.将上面的对象添加到appPhotoes中 [appPhotoes addObject:photo]; }]; _appPhotoes = appPhotoes; } }
相关文章推荐
- centos6.4安装sphinx(php)
- 版本控制
- cmake入门
- ubuntu12.04 MX28调试记录
- Swift 中类的初始化器与继承
- java 每日习题(五) 下落的小球
- sharepoint 通过数据库擅长列表项
- 融云会话里添加附加信息
- 超火|程序员加薪的新方法
- JAVA中如何将File::lastModified()日期转换为常规日期
- 第三方登陆
- 在这里安家家了
- Linux用户空间与内核空间
- 遇见了奇怪bug,前端用的AngularJs,后台是SpringMVC,持久用的hibernate,跟后台断点时查询数据库返回一条数据,否则返回两条,以下是问题详述
- 项目实战 网易彩票1
- onCreate中Bundle saveInstanceState的作用
- 动画的代理方法使用的 和 动画结束不会回复原来的样子
- cocoa pods
- 使用Ant给EJB项目编译、打包、发布
- Android性能优化之使用线程池处理异步任务