From 9b4e6f3de42406a57fcc843167d330b53a9ea736 Mon Sep 17 00:00:00 2001 From: xujia Date: Thu, 7 Dec 2017 14:51:24 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E8=BD=AC=E6=A8=A1=E5=9E=8B=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YYModel/NSObject+YYModel.h | 9 +++++++++ YYModel/NSObject+YYModel.m | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) mode change 100644 => 100755 YYModel/NSObject+YYModel.h mode change 100644 => 100755 YYModel/NSObject+YYModel.m diff --git a/YYModel/NSObject+YYModel.h b/YYModel/NSObject+YYModel.h old mode 100644 new mode 100755 index 73f62ec..e46a0a0 --- a/YYModel/NSObject+YYModel.h +++ b/YYModel/NSObject+YYModel.h @@ -102,6 +102,15 @@ NS_ASSUME_NONNULL_BEGIN */ + (nullable instancetype)yy_modelWithDictionary:(NSDictionary *)dictionary; + +/** + Creates and returns a new instance of the receiver from an array containing key-value dictionary, automatic parsing multiple array. + + @param keyValueArray An array containing key-value dictionary mapped to the instance's properties. + @return A new array containing instance. + */ ++ (NSMutableArray *)yy_modelArrayWithKeyValueArray:(NSArray *)keyValueArray; + /** Set the receiver's properties with a json object. diff --git a/YYModel/NSObject+YYModel.m b/YYModel/NSObject+YYModel.m old mode 100644 new mode 100755 index 3d7c470..c691459 --- a/YYModel/NSObject+YYModel.m +++ b/YYModel/NSObject+YYModel.m @@ -1454,6 +1454,25 @@ + (instancetype)yy_modelWithJSON:(id)json { return [self yy_modelWithDictionary:dic]; } ++ (NSMutableArray *)yy_modelArrayWithKeyValueArray:(NSArray *)keyValueArray { + if (!keyValueArray || keyValueArray == (id)kCFNull) return nil; + if (![keyValueArray isKindOfClass:[NSArray class]]) return nil; + NSMutableArray *modelArray = [NSMutableArray array]; + return [self _yy_modelArrayWithRecurArray:keyValueArray modelArray:modelArray];; +} + ++ (NSMutableArray *)_yy_modelArrayWithRecurArray:(NSArray *)array modelArray:(NSMutableArray *)modelArray { + [array enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:[NSArray class]]) { + NSMutableArray *array = [NSMutableArray array]; + [modelArray addObject:[self _yy_modelArrayWithRecurArray:obj modelArray:array]]; + } else { + [modelArray addObject:[self yy_modelWithDictionary:obj]]; + } + }]; + return modelArray; +} + + (instancetype)yy_modelWithDictionary:(NSDictionary *)dictionary { if (!dictionary || dictionary == (id)kCFNull) return nil; if (![dictionary isKindOfClass:[NSDictionary class]]) return nil; From 84afcb7e7ca6527e0f686cdca589a7bd6d015866 Mon Sep 17 00:00:00 2001 From: xujia Date: Thu, 7 Dec 2017 15:06:49 +0800 Subject: [PATCH 2/3] If contain anything else element except dictionary, method will return a uninitialized instance. --- YYModel/NSObject+YYModel.h | 2 +- YYModel/NSObject+YYModel.m | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/YYModel/NSObject+YYModel.h b/YYModel/NSObject+YYModel.h index e46a0a0..07f5afc 100755 --- a/YYModel/NSObject+YYModel.h +++ b/YYModel/NSObject+YYModel.h @@ -104,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN /** - Creates and returns a new instance of the receiver from an array containing key-value dictionary, automatic parsing multiple array. + Creates and returns a new instance of the receiver from an array containing key-value dictionary, automatic parsing multiple array, if contain anything else element except dictionary, mothed will return a uninitialized instance. @param keyValueArray An array containing key-value dictionary mapped to the instance's properties. @return A new array containing instance. diff --git a/YYModel/NSObject+YYModel.m b/YYModel/NSObject+YYModel.m index c691459..0e10f35 100755 --- a/YYModel/NSObject+YYModel.m +++ b/YYModel/NSObject+YYModel.m @@ -1467,6 +1467,9 @@ + (NSMutableArray *)_yy_modelArrayWithRecurArray:(NSArray *)array modelArray:(NS NSMutableArray *array = [NSMutableArray array]; [modelArray addObject:[self _yy_modelArrayWithRecurArray:obj modelArray:array]]; } else { + if (![obj isKindOfClass:[NSDictionary class]]) { + obj = [NSDictionary dictionary]; + } [modelArray addObject:[self yy_modelWithDictionary:obj]]; } }]; From 895d927fcef137816616d0625a6eb82552dfcca4 Mon Sep 17 00:00:00 2001 From: xujia Date: Thu, 7 Dec 2017 15:08:03 +0800 Subject: [PATCH 3/3] no message --- YYModel/NSObject+YYModel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YYModel/NSObject+YYModel.h b/YYModel/NSObject+YYModel.h index 07f5afc..4b6d6c0 100755 --- a/YYModel/NSObject+YYModel.h +++ b/YYModel/NSObject+YYModel.h @@ -104,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN /** - Creates and returns a new instance of the receiver from an array containing key-value dictionary, automatic parsing multiple array, if contain anything else element except dictionary, mothed will return a uninitialized instance. + Creates and returns a new instance of the receiver from an array containing key-value dictionary, automatic parsing multiple array, if contain anything else element except dictionary, method will return a uninitialized instance. @param keyValueArray An array containing key-value dictionary mapped to the instance's properties. @return A new array containing instance.