ios开发--字典转模型
来源:互联网 发布:网络歌手音频资料 编辑:程序博客网 时间:2024/05/27 20:51
app.plist文件内容如下
1. 先从程序路径下获取该文件内容
创建一个app类
+ (NSArray *)app { // 获取路径 NSString *path = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"plist"]; // 获取文件内容 NSArray *array = [NSArray arrayWithContentsOfFile:path]; // 模型转换 NSMutableArray *arrayM = [NSMutableArray array]; for (NSDictionary *dict in array) { [arrayM addObject:[self appWithDict:dict]]; } return arrayM;}
2. 字典转模型
- (instancetype)initWithDict:(NSDictionary *)dict { self = [super init]; if (self) { // KVC //[self setValuesForKeysWithDictionary:dict]; self.name = dict[@"name"]; self.icon = dict[@"icon"]; } return self;}
3. 获取app.plist中的内容
-(NSArray *)appList { if (!_appList) { _appList = [App app]; } return _appList;}- (void)viewDidLoad { [super viewDidLoad]; [self appList]; for (int i = 0; i < self.appList.count; i++) { App *app = self.appList[i]; NSLog(@"name = %@, icon = %@", app.name, app.icon); UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(10, 30 * (i+1), 150, 50); label.text = app.name; label.font = [UIFont systemFontOfSize:13]; [self.view addSubview:label]; } }
代码地址
0 0
- ios开发--字典转模型
- IOS开发UI字典转模型
- IOS开发- 03.字典转模型
- iOS开发之字典转模型
- iOS开发中的字典转模型应用
- iOS 开发-字典转模型
- iOS基础开发-字典转模型(模型思想)
- IOS字典转模型
- ios 字典转模型
- iOS 字典转模型
- iOS 字典转模型
- iOS 字典转模型
- ios-字典转模型
- iOS开发UI篇—字典转模型
- iOS开发UI篇—字典转模型
- 2、iOS 开发之字典转模型和 xib
- iOS开发UI篇—字典转模型
- iOS开发UI篇—字典转模型
- JAVA实现空间索引编码(GeoHash)
- java设计模式-策略模式
- [Noi 2015] 品酒大会
- 大战!贪心!SHU1951 Apple Trees
- PHP变量的声明及其作用域&静态变量
- ios开发--字典转模型
- ServerSocket服务器通信
- 106,Protocol的基本使用以及注意点
- Numpy中的argsort函数详解
- maven 插件动态打包
- C语言qsort库函数使用说明
- foxmail重复收取邮件解决办法及删除重复邮件办法
- 数学的幽默打油诗
- 1005: [HNOI2008]明明的烦恼