Skip to content

Commit 498303d

Browse files
committed
增强key替换的功能
1.优先调用mj_replacedKeyFromPropertyName121 2.其次调用mj_replacedKeyFromPropertyName
1 parent 4bce9b7 commit 498303d

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

MJExtension.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "MJExtension"
3-
s.version = "3.0.10"
3+
s.version = "3.0.11"
44
s.ios.deployment_target = '6.0'
55
s.osx.deployment_target = '10.8'
66
s.summary = "A fast and convenient conversion between JSON and model"

MJExtension/NSObject+MJKeyValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* @return 从字典中取值用的key
4040
*/
41-
+ (NSString *)mj_replacedKeyFromPropertyName121:(NSString *)propertyName;
41+
+ (id)mj_replacedKeyFromPropertyName121:(NSString *)propertyName;
4242

4343
/**
4444
* 数组中需要转换的模型类

MJExtension/NSObject+MJProperty.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef void (^MJPropertiesEnumeration)(MJProperty *property, BOOL *stop);
2121

2222
/** 将属性名换为其他key去字典中取值 */
2323
typedef NSDictionary * (^MJReplacedKeyFromPropertyName)();
24-
typedef NSString * (^MJReplacedKeyFromPropertyName121)(NSString *propertyName);
24+
typedef id (^MJReplacedKeyFromPropertyName121)(NSString *propertyName);
2525
/** 数组中需要转换的模型类 */
2626
typedef NSDictionary * (^MJObjectClassInArray)();
2727
/** 用于过滤字典中的值 */

MJExtension/NSObject+MJProperty.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ + (NSMutableDictionary *)dictForKey:(const void *)key
5353
}
5454

5555
#pragma mark - --私有方法--
56-
+ (NSString *)propertyKey:(NSString *)propertyName
56+
+ (id)propertyKey:(NSString *)propertyName
5757
{
5858
MJExtensionAssertParamNotNil2(propertyName, nil);
5959

60-
__block NSString *key = nil;
60+
__block id key = nil;
6161
// 查看有没有需要替换的key
6262
if ([self respondsToSelector:@selector(mj_replacedKeyFromPropertyName121:)]) {
6363
key = [self mj_replacedKeyFromPropertyName121:propertyName];
@@ -79,21 +79,21 @@ + (NSString *)propertyKey:(NSString *)propertyName
7979
}
8080

8181
// 查看有没有需要替换的key
82-
if (!key && [self respondsToSelector:@selector(mj_replacedKeyFromPropertyName)]) {
82+
if ((!key || [key isEqual:propertyName]) && [self respondsToSelector:@selector(mj_replacedKeyFromPropertyName)]) {
8383
key = [self mj_replacedKeyFromPropertyName][propertyName];
8484
}
8585
// 兼容旧版本
86-
if (!key && [self respondsToSelector:@selector(replacedKeyFromPropertyName)]) {
86+
if ((!key || [key isEqual:propertyName]) && [self respondsToSelector:@selector(replacedKeyFromPropertyName)]) {
8787
key = [self performSelector:@selector(replacedKeyFromPropertyName)][propertyName];
8888
}
8989

90-
if (!key) {
90+
if (!key || [key isEqual:propertyName]) {
9191
[self mj_enumerateAllClasses:^(__unsafe_unretained Class c, BOOL *stop) {
9292
NSDictionary *dict = objc_getAssociatedObject(c, &MJReplacedKeyFromPropertyNameKey);
9393
if (dict) {
9494
key = dict[propertyName];
9595
}
96-
if (key) *stop = YES;
96+
if (key && ![key isEqual:propertyName]) *stop = YES;
9797
}];
9898
}
9999

0 commit comments

Comments
 (0)