加载plist到模型数组

来源:互联网 发布:淘宝详情图图尺寸多少 编辑:程序博客网 时间:2024/06/05 15:00
@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];            // 3.2.添加模型对象到数组中            [heroArray addObject:hero];        }        // 4.赋值        _heros = heroArray;    }    return _heros;}
0 0
原创粉丝点击