Set方法 Get方法(懒加载) 重构方法 重写方法 自定义方法
2016-06-07 本文已影响812人
Sean_Jiang
-
(void)setShop
_shop = shop; 重写set方法是 成员变量 一定要重新 赋值
}
- (instancetype)init
{
if (self = [super init]) {
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
}
/**
- 懒加载
*/
-
(NSArray *)shops
{
if (_shops == nil) {NSString *path = [[NSBundle mainBundle] pathForResource:@"shops.plist" ofType:nil]; NSArray *dictArr = [NSArray arrayWithContentsOfFile:path]; NSMutableArray *shopArr = [NSMutableArray array]; for (NSDictionary *dict in dictArr) { JSShopModel *shop = [JSShopModel shopWithDict:dict]; [shopArr addObject:shop]; } _shops = shopArr;
}
return _shops;
}