Skip to content

Commit 662cae5

Browse files
committed
Merge branch 'pr/131'
2 parents f6a861a + 2a5fecb commit 662cae5

File tree

5 files changed

+29
-11
lines changed

5 files changed

+29
-11
lines changed

MJExtension/MJFoundation.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ @implementation MJFoundation
1717
+ (NSSet *)foundatonClasses
1818
{
1919
if (_foundationClasses == nil) {
20+
// 集合中没有NSObject,因为几乎所有的类都是继承自NSObject,具体是不是NSObject需要特殊判断
2021
_foundationClasses = [NSSet setWithObjects:
2122
[NSURL class],
2223
[NSDate class],
@@ -33,11 +34,17 @@ + (NSSet *)foundatonClasses
3334
+ (BOOL)isClassFromFoundation:(Class)c
3435
{
3536
__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]) {
3839
result = YES;
40+
*stop = YES;
3941
}
4042
}];
43+
44+
if (c == [NSObject class]) {
45+
result = YES;
46+
}
47+
4148
return result;
4249
}
4350
@end

MJExtension/MJProperty.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,29 @@ typedef enum {
1414
MJPropertyKeyTypeDictionary = 0, // 字典的key
1515
MJPropertyKeyTypeArray // 数组的key
1616
} MJPropertyKeyType;
17+
18+
1719
/**
1820
* 属性的key
1921
*/
2022
@interface MJPropertyKey : NSObject
21-
@property (copy, nonatomic) NSString *name;
23+
24+
@property (copy, nonatomic) NSString *name;
2225
@property (assign, nonatomic) MJPropertyKeyType type;
26+
2327
/**
24-
* 根据当前的key从object(字典或者数组)中取值
28+
* 根据当前的key,也就是name,从object(字典或者数组)中取值
2529
*/
26-
- (id)valueForObject:(id)object;
30+
- (id)valueInObject:(id)object;
31+
2732
@end
2833

34+
2935
/**
3036
* 包装一个成员
3137
*/
3238
@interface MJProperty : NSObject
39+
3340
/** 成员属性 */
3441
@property (nonatomic, assign) objc_property_t property;
3542
/** 成员属性名 */
@@ -40,6 +47,7 @@ typedef enum {
4047
/** 成员来源于哪个类(可能是父类) */
4148
@property (nonatomic, assign) Class srcClass;
4249

50+
4351
/**** 同一个成员变量 - 父类和子类的行为可能不一致(key、keys、objectClassInArray) ****/
4452
/** 对应着字典中的key */
4553
- (void)setKey:(NSString *)key forClass:(Class)c;
@@ -64,4 +72,5 @@ typedef enum {
6472
* 初始化
6573
*/
6674
+ (instancetype)cachedPropertyWithProperty:(objc_property_t)property;
75+
6776
@end

MJExtension/MJProperty.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@implementation MJPropertyKey
1414

15-
- (id)valueForObject:(id)object
15+
- (id)valueInObject:(id)object
1616
{
1717
if ([object isKindOfClass:[NSDictionary class]] && self.type == MJPropertyKeyTypeDictionary) {
1818
return object[self.name];
@@ -25,8 +25,10 @@ - (id)valueForObject:(id)object
2525
@end
2626

2727
@interface MJProperty()
28+
2829
@property (strong, nonatomic) NSMutableDictionary *propertyKeysDict;
2930
@property (strong, nonatomic) NSMutableDictionary *objectClassInArrayDict;
31+
3032
@end
3133

3234
@implementation MJProperty

MJExtension/NSObject+MJKeyValue.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ - (instancetype)setKeyValues:(id)keyValues context:(NSManagedObjectContext *)con
128128
id value = keyValues ;
129129
NSArray *propertyKeys = [property propertyKeysFromClass:[self class]];
130130
for (MJPropertyKey *propertyKey in propertyKeys) {
131-
value = [propertyKey valueForObject:value];
131+
value = [propertyKey valueInObject:value];
132132
}
133133

134134
// 值的过滤
@@ -350,7 +350,7 @@ - (NSMutableDictionary *)keyValuesWithKeys:(NSArray *)keys ignoredKeys:(NSArray
350350

351351
if (nextPropertyKey) { // 不是最后一个key
352352
// 当前propertyKey对应的字典或者数组
353-
id tempInnerContainer = [propertyKey valueForObject:innerContainer];
353+
id tempInnerContainer = [propertyKey valueInObject:innerContainer];
354354
if (tempInnerContainer == nil || [tempInnerContainer isKindOfClass:[NSNull class]]) {
355355
if (nextPropertyKey.type == MJPropertyKeyTypeDictionary) {
356356
tempInnerContainer = [NSMutableDictionary dictionary];

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,9 @@ NSDictionary *dict = @{
305305
@"info" : @[
306306
@"test-data",
307307
@{
308-
@"nameChangedTime" : @"2013-08"
309-
}
310-
}]
308+
@"nameChangedTime" : @"2013-08"
309+
}
310+
]
311311
},
312312
@"other" : @{
313313
@"bag" : @{

0 commit comments

Comments
 (0)