File tree Expand file tree Collapse file tree 5 files changed +29
-11
lines changed Expand file tree Collapse file tree 5 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ @implementation MJFoundation
17
17
+ (NSSet *)foundatonClasses
18
18
{
19
19
if (_foundationClasses == nil ) {
20
+ // 集合中没有NSObject,因为几乎所有的类都是继承自NSObject,具体是不是NSObject需要特殊判断
20
21
_foundationClasses = [NSSet setWithObjects:
21
22
[NSURL class ],
22
23
[NSDate class ],
@@ -33,11 +34,17 @@ + (NSSet *)foundatonClasses
33
34
+ (BOOL )isClassFromFoundation : (Class )c
34
35
{
35
36
__block BOOL result = NO ;
36
- [[self foundatonClasses ] enumerateObjectsUsingBlock: ^(Class obj , BOOL *stop) {
37
- if (c == [ NSObject class ] || c == obj || [c isSubclassOfClass: obj ]) {
37
+ [[self foundatonClasses ] enumerateObjectsUsingBlock: ^(Class foundationClass , BOOL *stop) {
38
+ if (c == foundationClass || [c isSubclassOfClass: foundationClass ]) {
38
39
result = YES ;
40
+ *stop = YES ;
39
41
}
40
42
}];
43
+
44
+ if (c == [NSObject class ]) {
45
+ result = YES ;
46
+ }
47
+
41
48
return result;
42
49
}
43
50
@end
Original file line number Diff line number Diff line change @@ -14,22 +14,29 @@ typedef enum {
14
14
MJPropertyKeyTypeDictionary = 0 , // 字典的key
15
15
MJPropertyKeyTypeArray // 数组的key
16
16
} MJPropertyKeyType;
17
+
18
+
17
19
/* *
18
20
* 属性的key
19
21
*/
20
22
@interface MJPropertyKey : NSObject
21
- @property (copy , nonatomic ) NSString *name;
23
+
24
+ @property (copy , nonatomic ) NSString *name;
22
25
@property (assign , nonatomic ) MJPropertyKeyType type;
26
+
23
27
/* *
24
- * 根据当前的key从object (字典或者数组)中取值
28
+ * 根据当前的key,也就是name,从object (字典或者数组)中取值
25
29
*/
26
- - (id )valueForObject : (id )object ;
30
+ - (id )valueInObject : (id )object ;
31
+
27
32
@end
28
33
34
+
29
35
/* *
30
36
* 包装一个成员
31
37
*/
32
38
@interface MJProperty : NSObject
39
+
33
40
/* * 成员属性 */
34
41
@property (nonatomic , assign ) objc_property_t property;
35
42
/* * 成员属性名 */
@@ -40,6 +47,7 @@ typedef enum {
40
47
/* * 成员来源于哪个类(可能是父类) */
41
48
@property (nonatomic , assign ) Class srcClass;
42
49
50
+
43
51
/* *** 同一个成员变量 - 父类和子类的行为可能不一致(key、keys、objectClassInArray) ****/
44
52
/* * 对应着字典中的key */
45
53
- (void )setKey : (NSString *)key forClass : (Class )c ;
@@ -64,4 +72,5 @@ typedef enum {
64
72
* 初始化
65
73
*/
66
74
+ (instancetype )cachedPropertyWithProperty : (objc_property_t )property ;
75
+
67
76
@end
Original file line number Diff line number Diff line change 12
12
13
13
@implementation MJPropertyKey
14
14
15
- - (id )valueForObject : (id )object
15
+ - (id )valueInObject : (id )object
16
16
{
17
17
if ([object isKindOfClass: [NSDictionary class ]] && self.type == MJPropertyKeyTypeDictionary) {
18
18
return object[self .name];
@@ -25,8 +25,10 @@ - (id)valueForObject:(id)object
25
25
@end
26
26
27
27
@interface MJProperty ()
28
+
28
29
@property (strong , nonatomic ) NSMutableDictionary *propertyKeysDict;
29
30
@property (strong , nonatomic ) NSMutableDictionary *objectClassInArrayDict;
31
+
30
32
@end
31
33
32
34
@implementation MJProperty
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ - (instancetype)setKeyValues:(id)keyValues context:(NSManagedObjectContext *)con
128
128
id value = keyValues ;
129
129
NSArray *propertyKeys = [property propertyKeysFromClass: [self class ]];
130
130
for (MJPropertyKey *propertyKey in propertyKeys) {
131
- value = [propertyKey valueForObject : value];
131
+ value = [propertyKey valueInObject : value];
132
132
}
133
133
134
134
// 值的过滤
@@ -350,7 +350,7 @@ - (NSMutableDictionary *)keyValuesWithKeys:(NSArray *)keys ignoredKeys:(NSArray
350
350
351
351
if (nextPropertyKey) { // 不是最后一个key
352
352
// 当前propertyKey对应的字典或者数组
353
- id tempInnerContainer = [propertyKey valueForObject : innerContainer];
353
+ id tempInnerContainer = [propertyKey valueInObject : innerContainer];
354
354
if (tempInnerContainer == nil || [tempInnerContainer isKindOfClass: [NSNull class ]]) {
355
355
if (nextPropertyKey.type == MJPropertyKeyTypeDictionary) {
356
356
tempInnerContainer = [NSMutableDictionary dictionary ];
Original file line number Diff line number Diff line change @@ -305,9 +305,9 @@ NSDictionary *dict = @{
305
305
@"info" : @[
306
306
@"test-data",
307
307
@{
308
- @"nameChangedTime" : @"2013-08"
309
- }
310
- } ]
308
+ @"nameChangedTime" : @"2013-08"
309
+ }
310
+ ]
311
311
},
312
312
@"other" : @{
313
313
@"bag" : @{
You can’t perform that action at this time.
0 commit comments