码迷,mamicode.com
首页 > 移动开发 > 详细

IOS中级篇 —— 字典转模型

时间:2015-06-23 15:05:57      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

@property (nonatomic, copy) NSString *icon;
@property (nonatomic, copy) NSString *name;

-(
instancetype) initWithDic:(NSDictionary *)dic;

+(instancetype) appViewWithDic:(NSDictionary *)dic;

-(instancetype)initWithDic:(NSDictionary *)dic{
?? if ([super init]) {
??????? _icon = dic[@"icon"];
???????
_name = dic[@"name"];
??? }
???
return self;
}

+(
instancetype)appViewWithDic:(NSDictionary *)dic
{
???
return [[self alloc] initWithDic:dic];
}

?
-(NSArray *)apps{
???
if (!_apps) {
???????
NSString *path = [[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil];
???????
NSArray *array = [NSArray arrayWithContentsOfFile:path];
???????
NSMutableArray *mArray = [NSMutableArray array];
???????
for (NSDictionary *dic in array) {
???????????
appViewModel *model = [appViewModel appViewWithDic:dic];
??????????? [mArray
addObject:model];
??????? }
???????
_apps = mArray;
??? }
???
return? _apps;
}


如果在外部用来模型来做为成员变量 ?一定要重新模型变量的set方法 ? 否则没值
?

IOS中级篇 —— 字典转模型

标签:

原文地址:http://www.cnblogs.com/deng1989/p/4595277.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!