设为首页 加入收藏

TOP

Objective - C 中的KVC(一)(视图、便携、易懂、原创纯手打 定制版)(二)
2017-10-13 10:33:17 】 浏览:4470
Tags:Objective KVC 视图 便携 易懂 原创 制版
copy, readonly) NSString *name; 14 15 @property (nonatomic, assign, readonly) NSInteger height; 16 17 + (NSArray *)loadData; 18 19 @end

model.h

 

 1 //
 2 //  Model.m
 3 //  KVC熟悉与加强
 4 //
 5 //  Created by ma c on 16/5/16.
 6 //  Copyright © 2016年 彭盛凇. All rights reserved.
 7 //
 8 
 9 #import "Model.h"
10 
11 @implementation Model
12 
13 - (NSString *)description
14 {
15     return [NSString stringWithFormat:@"model.name = %@, mdoel.height = %@", _name, @(_height)];
16 }
17 
18 - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
19     
20     NSLog(@"key = %@没有找到",key);
21     
22 }
23 
24 + (NSArray *)loadData {
25     
26     //获取plist文件路径
27     NSString *path = @"/Users/mac/Desktop/KVC熟悉与加强/KVC熟悉与加强/CoderPSS.plist";
28     
29     //获取plist文件中的数组
30     NSArray *array = [NSArray arrayWithContentsOfFile:path];
31     
32     //初始化可变数组
33     NSMutableArray *dataList = [NSMutableArray array];
34     
35     //使用字典遍历plist中的数组
36     for (NSDictionary *dict in array) {
37         
38         //初始化model类
39         Model *model = [[Model alloc] init];
40         
41         //使用KVC(setValuesForKeysWithDictionary)方法解析数据
42         [model setValuesForKeysWithDictionary:dict];
43         
44         //将model类加到可变数组
45         [dataList addObject:model];
46     }
47     
48     //返回可变数组
49     return dataList;
50 }
51 
52 @end

运行结果

 

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇OC NSSet 下一篇【代码笔记】iOS-清除缓存有黑色..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目