懒加载
在get中加载,且只加载一次
- (NSArray *)shops
{
if (_shops == nil) {
NSString *file = [[NSBundle mainBundle] pathForResource:@"shops" ofType:@"plist"];
self.shops = [NSArray arrayWithContentsOfFile:file];
// _shops = [NSArray arrayWithContentsOfFile:file];
// [self setShops:[NSArray arrayWithContentsOfFile:file]];
}
return _shops;
}
模型
根据具体业务数据来确定的数据模型,可以替代NSDictionary
自定义代码片段
用<#param#>来设置变量
重写构造方法
- (instancetype)initWithDict:(NSDictionary *)dict
{
if (self = [super init]) {
self.name = dict[@"name"];
self.icon = dict[@"icon"];
}
return self;
}
+ (instancetype)shopWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}