ios中 读出.plist中的NSArray 并保存到model中

读取文件

//0.1获取bundle
NSBundle *mainBundle=[NSBundle mainBundle];
//0.2获取路径
NSString *path=[mainBundle pathForResource:@"images.plist" ofType:nil];
//0.3初始化数组
NSArray *tempArr=[NSArray arrayWithContentsOfFile:path];
NSMutableArray *mutArr=[NSMutableArray array];
for (NSDictionary *dic in tempArr) {
    ImageModel *newImageMod=[[ImageModel alloc]initWithDic:dic];
    [mutArr addObject:newImageMod];
}

ImageModel.h

#import <Foundation/Foundation.h>

@interface ImageModel : NSObject

@property (strong,nonatomic)NSString *desc;
@property (strong,nonatomic)NSString *icon;

- (instancetype)initWithDic:(NSDictionary *)dic;
- 
@end

ImageModel.m

#import "ImageModel.h"

@implementation ImageModel

- (instancetype)initWithDic:(NSDictionary *)dic{
    if (self=[super init]) {
        self.desc=dic[@"desc"];
        self.icon=dic[@"icon"];
    }
    return self;

}

@end

猜你喜欢

转载自blog.csdn.net/a136447572/article/details/79177927
今日推荐