美文网首页
懒加载和懒加载字典转模型

懒加载和懒加载字典转模型

作者: Hevin_Chen | 来源:发表于2016-09-18 20:43 被阅读35次

 懒加载

// 懒加载

- (NSArray *)shops

{

if (_shops == nil) {

NSString *file = [[NSBundle mainBundle]pathForResource:@"shops" ofType:@"plist"];

_shops = [NSArray arrayWithContentsOfFile:file];

}

return _shops;

懒加载字典转模型

// 懒加载字典转模型

- (NSArray *)shops

{

if (_shops == nil) {

NSArray *dictArray= [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"shops" ofType:@"plist"]];

NSMutableArray *shopArray = [NSMutableArray array];

for (NSDictionary *dict in dictArray) {

HCShop *shop = [HCShop shopWithDict:dict];

[shopArray addObject:shop];

}

_shops = shopArray;

}

return _shops;

}

相关文章

网友评论

      本文标题:懒加载和懒加载字典转模型

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