接上昨晚的数据源继续用,然后将自动生成的属性贴在模型中
# .h 文件中是属性(就不用我写了吧 T_T)
#模型的属性名跟字典 -- 一 一对应
+ (__kindof Model *)modelWithDict:(NSDictionary *)dict;
#
# .m 文件中
+ (__kindof Model *)modelWithDict:(NSDictionary *)dict{
Model *model = [[Model alloc] init];
[model setValueForKeysWithDictionary:dict];
return model;
}
#viewController中
NSMutableArray *models = [NSMutableArray array];
for (NSDictionary *dict in dictArr){
Model *modle = [Model modelWithDict:dict];
[models addOBject:model];
}
NSLog(@"%@",models);
途中会报的错误
#在model.m文件中重写系统的报错方法
- (void)setValue:(id)value forUNdefinedKey:(NSString *)key{
if([key isEqualToString:@"id"]){
_ID = [value integerValue];
}
NSLog(@"%@ --- %@",key ,value);
}

这里就结束了,明天再跟进用runtime实现。晚安,好梦。