-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSObject+JKExtension.h
52 lines (37 loc) · 1.22 KB
/
NSObject+JKExtension.h
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
//
// NSObject+JKExtension.h
// 利用 runtime
//
// Created by 李佳贵 on 16/4/22.
// Copyright © 2016年 李佳贵. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (JKExtension)
//0. --------字典转模型相关-----
// 获取所有属性数组里存的什么类型的数据,生成一个 @{@"数组属性名1" : @"所存模型类型1",@"数组属性名2" : @"所存模型类型2"}
// 如果不声明则给对应的属性赋值为字典数组 或者是 字符串数组
- (NSDictionary *)objectClassInProArray;
// 字典转模型
- (void)setDict:(NSDictionary *)dict;
+ (instancetype)objectWithDict:(NSDictionary *)dict;
//1. ---------归档相关---------
// 如果有不需要归档的属性,请实现此方法,返回需要忽略的参数名
// eg. return @[@"name"] 或者 return @[@"_name"] 两个效果一样
- (NSArray *)ignoreNames;
- (void)encode:(NSCoder *)encoder;
- (instancetype)decode:(NSCoder *)decoder;
#define JKCodingImplement \
- (void)encodeWithCoder:(NSCoder *)encoder\
{\
[self encode:encoder];\
\
}\
- (instancetype)initWithCoder:(NSCoder *)decoder\
{\
self = [super init];\
if (self) {\
[self decode:decoder];\
}\
return self;\
}
@end