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

2016-09-18  本文已影响35人  Hevin_Chen

 懒加载

// 懒加载

- (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;

}

上一篇 下一篇

猜你喜欢

热点阅读