From 93a9c94ba0c697e4e08d672d1302d738f9c88120 Mon Sep 17 00:00:00 2001 From: Denys Telezhkin Date: Sun, 7 Dec 2014 16:23:09 +0200 Subject: [PATCH] closes #70 --- EasyMapping/EKMapper.m | 14 ++++++++++++++ EasyMapping/EKPropertyHelper.m | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/EasyMapping/EKMapper.m b/EasyMapping/EKMapper.m index e84c5af..d746f20 100644 --- a/EasyMapping/EKMapper.m +++ b/EasyMapping/EKMapper.m @@ -31,6 +31,15 @@ @implementation EKMapper + (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKObjectMapping *)mapping { + NSParameterAssert([externalRepresentation isKindOfClass:[NSDictionary class]]); + NSParameterAssert([mapping isKindOfClass:[EKObjectMapping class]]); + + if (![externalRepresentation isKindOfClass:[NSDictionary class]] || + ![mapping isKindOfClass:[EKObjectMapping class]]) + { + return nil; + } + id object = [[mapping.objectClass alloc] init]; return [self fillObject:object fromExternalRepresentation:externalRepresentation withMapping:mapping]; } @@ -76,6 +85,11 @@ + (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalReprese NSParameterAssert([externalRepresentation isKindOfClass:[NSArray class]]); NSParameterAssert([mapping isKindOfClass:[EKObjectMapping class]]); + if (![externalRepresentation isKindOfClass:[NSArray class]] || + ![mapping isKindOfClass:[EKObjectMapping class]]) { + return nil; + } + NSMutableArray *array = [NSMutableArray array]; for (NSDictionary *representation in externalRepresentation) { id parsedObject = [self objectFromExternalRepresentation:representation withMapping:mapping]; diff --git a/EasyMapping/EKPropertyHelper.m b/EasyMapping/EKPropertyHelper.m index c3630e5..5b4eb4e 100644 --- a/EasyMapping/EKPropertyHelper.m +++ b/EasyMapping/EKPropertyHelper.m @@ -64,6 +64,11 @@ + (NSString *) propertyTypeStringRepresentationFromProperty:(objc_property_t)pro + (id)propertyRepresentation:(NSArray *)array forObject:(id)object withPropertyName:(NSString *)propertyName { + if (!array) + { + return nil; + } + objc_property_t property = class_getProperty([object class], [propertyName UTF8String]); if (property) {