From 498303dbb55fa111dbe6c688bf8f55e0be377c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=E4=BA=86=E4=B8=AAJ?= Date: Thu, 30 Jun 2016 09:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BAkey=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.优先调用mj_replacedKeyFromPropertyName121 2.其次调用mj_replacedKeyFromPropertyName --- MJExtension.podspec | 2 +- MJExtension/NSObject+MJKeyValue.h | 2 +- MJExtension/NSObject+MJProperty.h | 2 +- MJExtension/NSObject+MJProperty.m | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/MJExtension.podspec b/MJExtension.podspec index 61ec3d4e..f312ea72 100644 --- a/MJExtension.podspec +++ b/MJExtension.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MJExtension" - s.version = "3.0.10" + s.version = "3.0.11" s.ios.deployment_target = '6.0' s.osx.deployment_target = '10.8' s.summary = "A fast and convenient conversion between JSON and model" diff --git a/MJExtension/NSObject+MJKeyValue.h b/MJExtension/NSObject+MJKeyValue.h index e2319405..2428a4ab 100755 --- a/MJExtension/NSObject+MJKeyValue.h +++ b/MJExtension/NSObject+MJKeyValue.h @@ -38,7 +38,7 @@ * * @return 从字典中取值用的key */ -+ (NSString *)mj_replacedKeyFromPropertyName121:(NSString *)propertyName; ++ (id)mj_replacedKeyFromPropertyName121:(NSString *)propertyName; /** * 数组中需要转换的模型类 diff --git a/MJExtension/NSObject+MJProperty.h b/MJExtension/NSObject+MJProperty.h index 1a64732b..e4e0ebb1 100644 --- a/MJExtension/NSObject+MJProperty.h +++ b/MJExtension/NSObject+MJProperty.h @@ -21,7 +21,7 @@ typedef void (^MJPropertiesEnumeration)(MJProperty *property, BOOL *stop); /** 将属性名换为其他key去字典中取值 */ typedef NSDictionary * (^MJReplacedKeyFromPropertyName)(); -typedef NSString * (^MJReplacedKeyFromPropertyName121)(NSString *propertyName); +typedef id (^MJReplacedKeyFromPropertyName121)(NSString *propertyName); /** 数组中需要转换的模型类 */ typedef NSDictionary * (^MJObjectClassInArray)(); /** 用于过滤字典中的值 */ diff --git a/MJExtension/NSObject+MJProperty.m b/MJExtension/NSObject+MJProperty.m index 9ac6134c..fd7197a0 100644 --- a/MJExtension/NSObject+MJProperty.m +++ b/MJExtension/NSObject+MJProperty.m @@ -53,11 +53,11 @@ + (NSMutableDictionary *)dictForKey:(const void *)key } #pragma mark - --私有方法-- -+ (NSString *)propertyKey:(NSString *)propertyName ++ (id)propertyKey:(NSString *)propertyName { MJExtensionAssertParamNotNil2(propertyName, nil); - __block NSString *key = nil; + __block id key = nil; // 查看有没有需要替换的key if ([self respondsToSelector:@selector(mj_replacedKeyFromPropertyName121:)]) { key = [self mj_replacedKeyFromPropertyName121:propertyName]; @@ -79,21 +79,21 @@ + (NSString *)propertyKey:(NSString *)propertyName } // 查看有没有需要替换的key - if (!key && [self respondsToSelector:@selector(mj_replacedKeyFromPropertyName)]) { + if ((!key || [key isEqual:propertyName]) && [self respondsToSelector:@selector(mj_replacedKeyFromPropertyName)]) { key = [self mj_replacedKeyFromPropertyName][propertyName]; } // 兼容旧版本 - if (!key && [self respondsToSelector:@selector(replacedKeyFromPropertyName)]) { + if ((!key || [key isEqual:propertyName]) && [self respondsToSelector:@selector(replacedKeyFromPropertyName)]) { key = [self performSelector:@selector(replacedKeyFromPropertyName)][propertyName]; } - if (!key) { + if (!key || [key isEqual:propertyName]) { [self mj_enumerateAllClasses:^(__unsafe_unretained Class c, BOOL *stop) { NSDictionary *dict = objc_getAssociatedObject(c, &MJReplacedKeyFromPropertyNameKey); if (dict) { key = dict[propertyName]; } - if (key) *stop = YES; + if (key && ![key isEqual:propertyName]) *stop = YES; }]; }