黑马程序员--字典转模型
来源:互联网 发布:ubuntu和ubuntu mate 编辑:程序博客网 时间:2024/06/06 02:33
if (_appPlist == nil) {
// _appPlist = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]];
NSArray *array =[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]];
NSMutableArray *arrayM = [[NSMutableArray alloc] init];
for (NSDictionary *dict in array) {
// appInfo *appinfo = [appInfo appInfoWithDict:dict];
// appInfo *appinfo = [[appInfo alloc] initWithDict:dict];
// appinfo.name = dict[@"name"];
// appinfo.icon = dict[@"icon"];
[arrayM addObject:[appInfo appInfoWithDict:dict]];
}
_appPlist = arrayM;
}
return _appPlist;
转模型过程中,appInfo 自定义 initWithDict方法
/**
使用KVC的注意事项
1> plist中的键值名称必须与模型中的属性一致
2> 模型中的属性可以不全部出现在plist中
*/
- (instancetype)initWithDict:(NSDictionary *)dict
{
self = [super init];
if (self) {
// _name = dict[@"name"];
// _icon = dict[@"icon"];
// [self setValue:dict[@"name"] forKeyPath:@"name"];
// [self setValue:dict[@"icon"] forKeyPath:@"icon"];
[self setValuesForKeysWithDictionary:dict]; //KVC
}
return self;
}
+(instancetype)appInfoWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
- 黑马程序员--字典转模型
- 黑马程序员----字典、NSDictionary
- 黑马程序员---NSDictionary字典
- 字典转模型时,字典包含字典
- 自定义模型转字典,字典转模型
- 字典转模型
- 字典转模型
- 字典转模型
- 字典转模型
- 字典转模型
- —字典转模型
- 字典转模型
- IOS字典转模型
- ios 字典转模型
- UI012---字典转模型
- 字典转模型
- 转载;字典转模型
- 字典转模型
- class struct关键字区别
- 黑马程序员--搭建界面,九宫格
- 重新开始拾起我的安卓之路,什么时候开始都不算晚!!!!
- Zookeeper 在Hadoop中的应用
- Android开发:GridView与ListView相互切换(动画效果)
- 黑马程序员--字典转模型
- Lua利用元表实现修饰器
- 【面试题】-二叉树
- linux修改hostname
- alert();
- 黑马程序员--数组 排序
- 抽象和接口:
- js斐波那契数列求和
- html meta标签详解