@property (nonatomic, strong) NSArray *heros;
(NSArray *)heros
{
if (_heros == nil) {
// 初始化
// 1.获得 plist 的全路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil];// 2.加载数组 NSArray *dictArray = [NSArray arrayWithContentsOfFile:path]; // 3.将 dictArray 里面的所有字典转成模型对象,放到新的数组中 NSMutableArray *heroArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { // 3.1.创建模型对象 MJHero *hero = [MJHero heroWithDict:dict]; NSLog(@"%@",hero); // 3.2.添加模型对象到数组中 [heroArray addObject:hero]; } // 4.赋值 _heros = heroArray;}
return _heros;
}
代码如上,为什么没有调用 heros 却能获得 renturn 的对象? iOS 新手衷心求指教,想了好久都没想到是为什么,怀疑我自己是不是知识点缺失了。。。