-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSDataModel.podspec
More file actions
103 lines (76 loc) · 3.62 KB
/
CSDataModel.podspec
File metadata and controls
103 lines (76 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
# Be sure to run `pod lib lint CSDataModel.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'CSDataModel'
s.version = '1.1.1'
s.summary = '一个简单的数据模型基类,方便将NSDictionary、NSArray等类型数据转为模型对象'
s.description = <<-DESC
# CSDataModel
一个简单的数据模型基类,方便将NSDictionary、NSArray等类型数据转为模型对象
## 基本使用
例如一个JSON对象Department
{
"name": "DepartmentA",
"tel": "88888888",
"num": 1
}
该JSON String转化成NSDictionary: dict1
### 模型:
@interface Department : CSBaseModel
@property (nonatomic , strong) NSString *name;
@property (nonatomic , strong) NSString *tel;
@property (nonatomic , strong) NSNumber *num;
@end
### 转化时:
Department *deprtmt = [Department modelFromDict:dict1];
## 嵌套使用
### 模型
对于常见的情况:
{
"name": "departmentA",
"number": 3,
"members": [{
"name": "王五",
"jobNum": "0023"
},
{
"name": "陈六",
"jobNum": "0028"
}]
}
该JSON String转化成NSDictionary: dict2
Department中含有成员Member
@interface Department : CSBaseModel
@property (nonatomic , strong) NSString *name;
@property (nonatomic , strong) NSArray<Member*> *members;
@end
@interface Member : CSBaseModel
@property (nonatomic , strong) NSString *name;
@property (nonatomic , strong) NSNumber *jobNum;
@end
Deparmtent实现文件中需要注册子模型的类
@implementation Department
-(instancetype)init{
self = [super init];
if (self) {
[self registerClass:[Member class] forProperty:@"members"];
}
return self;
}
@end
### 转化时:
Department *deprtmt = [Department modelFromDict:dict2];
转化成功后,可通过deprtmt.members访问member数组
DESC
s.homepage = 'https://github.com/csdq/CSDataModel'
s.license = { :type => 'GPL-3.0', :file => 'LICENSE' }
s.source = { :git => 'https://github.com/csdq/CSDataModel.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.source_files = 'CSDataModel/Classes/**/*'
end