From 9751407684a9c31fea0ddfa5a6c9196075de1285 Mon Sep 17 00:00:00 2001 From: Denys Telezhkin Date: Fri, 23 Jan 2015 15:56:24 +0200 Subject: [PATCH] refactor incremental mapping to use a property on EKObjectMapping --- EasyMapping/EKManagedObjectMapper.h | 82 ----------------- EasyMapping/EKManagedObjectMapper.m | 92 ++++--------------- EasyMapping/EKMapper.h | 18 ---- EasyMapping/EKMapper.m | 13 +-- EasyMapping/EKObjectMapping.h | 5 + EasyMapping/EKPropertyHelper.m | 2 +- .../Tests/Specs/EKManagedObjectMapperSpec.m | 28 ++++-- EasyMappingExample/Tests/Specs/EKMapperSpec.m | 13 ++- 8 files changed, 53 insertions(+), 200 deletions(-) diff --git a/EasyMapping/EKManagedObjectMapper.h b/EasyMapping/EKManagedObjectMapper.h index 90d9033..5bbda62 100644 --- a/EasyMapping/EKManagedObjectMapper.h +++ b/EasyMapping/EKManagedObjectMapper.h @@ -44,24 +44,6 @@ withMapping:(EKManagedObjectMapping *)mapping inManagedObjectContext:(NSManagedObjectContext*)context; -/** - Creates object from JSON representation, using `mapping` in `context`. If incrementalData is true, to-many relationship data is pushed to the existing data instead of replaced. - - @param externalRepresentation JSON representation of object data - - @param mapping object mapping - - @param context managed object context to perform object creation - - @param incrementalData Defines if to-many relationship data is pushed or replaced - - @result mapped managed object - */ -+ (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - inManagedObjectContext:(NSManagedObjectContext*)context - incrementalData:(BOOL)incrementalData; - /** Fills previously existed object with values, provided in JSON representation. All values, that are included in mapping and were filled prior to calling this method, will be overwritten. @@ -80,27 +62,6 @@ withMapping:(EKManagedObjectMapping *)mapping inManagedObjectContext:(NSManagedObjectContext*)context; -/** - Fills previously existed object with values, provided in JSON representation. All values, that are included in mapping and were filled prior to calling this method, will be overwritten. If incrementalData is true, to-many relationship data is pushed to the existing data instead of replaced. - - @param object Object to fill - - @param externalRepresentation JSON representation of object data - - @param mapping object mapping - - @param context managed object context to perform object creation - - @param incrementalData Defines if to-many relationship data is pushed or replaced - - @result filled managed object - */ -+ (id) fillObject:(id)object - fromExternalRepresentation:(NSDictionary *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - inManagedObjectContext:(NSManagedObjectContext*)context - incrementalData:(BOOL)incrementalData; - /** Create array of CoreData objects. If passed JSON contains primary keys, previously existing object with these keys will be updated. Simply put, this method uses Find-Or-Create pattern. @@ -116,24 +77,6 @@ withMapping:(EKManagedObjectMapping *)mapping inManagedObjectContext:(NSManagedObjectContext*)context; -/** - Create array of CoreData objects. If passed JSON contains primary keys, previously existing object with these keys will be updated. Simply put, this method uses Find-Or-Create pattern. If incrementalData is true, to-many relationship data is pushed to the existing data instead of replaced. - - @param externalRepresentation JSON array with objects - - @param mapping object mapping - - @param context managed object context to perform objects creation - - @param incrementalData Defines if to-many relationship data is pushed or replaced - - @result array of managed objects - */ -+ (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - inManagedObjectContext:(NSManagedObjectContext*)context - incrementalData:(BOOL)incrementalData; - /** Synchronize the objects in the managed object context with the objects from an external representation. Any new objects will be created, any existing objects will be updated @@ -155,29 +98,4 @@ fetchRequest:(NSFetchRequest*)fetchRequest inManagedObjectContext:(NSManagedObjectContext *)context; -/** - Synchronize the objects in the managed object context with the objects from an external - representation. Any new objects will be created, any existing objects will be updated - and any object not present in the external representation will be deleted from the - managed object context. The fetch request is used to pre-fetch all existing objects. - If incrementalData is true, to-many relationship data is pushed to the existing data instead of replaced. - - @param externalRepresentation JSON array with objects - - @param mapping object mapping - - @param fetchRequest Fetch request to get existing objects - - @param context managed object context to perform objects creation - - @param incrementalData Defines if to-many relationship data is pushed or replaced - - @result array of managed objects - */ -+ (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - fetchRequest:(NSFetchRequest*)fetchRequest - inManagedObjectContext:(NSManagedObjectContext *)context - incrementalData:(BOOL)incrementalData; - @end diff --git a/EasyMapping/EKManagedObjectMapper.m b/EasyMapping/EKManagedObjectMapper.m index 8225d33..711df99 100644 --- a/EasyMapping/EKManagedObjectMapper.m +++ b/EasyMapping/EKManagedObjectMapper.m @@ -44,7 +44,6 @@ + (instancetype)mapperWithImporter:(EKCoreDataImporter *)importer - (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping - incrementalData:(BOOL)incrementalData { NSManagedObject * object = [self.importer existingObjectForRepresentation:externalRepresentation mapping:mapping @@ -56,8 +55,7 @@ - (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation } NSManagedObject * filledObject = [self fillObject:object fromExternalRepresentation:externalRepresentation - withMapping:mapping - incrementalData:incrementalData]; + withMapping:mapping]; [self.importer cacheObject:filledObject withMapping:mapping]; return filledObject; @@ -65,7 +63,6 @@ - (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation - (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping - incrementalData:(BOOL)incrementalData { NSDictionary * representation = [EKPropertyHelper extractRootPathFromExternalRepresentation:externalRepresentation withMapping:mapping]; @@ -76,31 +73,30 @@ - (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalR fromRepresentation:representation inContext:self.importer.context]; }]; - [mapping.hasOneMappings enumerateKeysAndObjectsUsingBlock:^(id key, EKRelationshipMapping * mapping, BOOL * stop) + [mapping.hasOneMappings enumerateKeysAndObjectsUsingBlock:^(id key, EKRelationshipMapping * relationship, BOOL * stop) { - NSDictionary * value = [mapping extractObjectFromRepresentation:representation]; + NSDictionary * value = [relationship extractObjectFromRepresentation:representation]; if (value && value != (id)[NSNull null]) { - id result = [self objectFromExternalRepresentation:value withMapping:(EKManagedObjectMapping *)[mapping objectMapping] incrementalData:incrementalData]; - [EKPropertyHelper setValue:result onObject:object forKeyPath:mapping.property]; + id result = [self objectFromExternalRepresentation:value withMapping:(EKManagedObjectMapping *)[relationship objectMapping]]; + [EKPropertyHelper setValue:result onObject:object forKeyPath:relationship.property]; } }]; - [mapping.hasManyMappings enumerateKeysAndObjectsUsingBlock:^(id key, EKRelationshipMapping * mapping, BOOL * stop) + [mapping.hasManyMappings enumerateKeysAndObjectsUsingBlock:^(id key, EKRelationshipMapping * relationship, BOOL * stop) { NSArray * arrayToBeParsed = [representation valueForKeyPath:key]; if (arrayToBeParsed && arrayToBeParsed != (id)[NSNull null]) { NSArray * parsedArray = [self arrayOfObjectsFromExternalRepresentation:arrayToBeParsed - withMapping:(EKManagedObjectMapping *)[mapping objectMapping] - incrementalData:incrementalData]; + withMapping:(EKManagedObjectMapping *)[relationship objectMapping]]; id parsedObjects = [EKPropertyHelper propertyRepresentation:parsedArray forObject:object - withPropertyName:[mapping property]]; - if(incrementalData) { - [EKPropertyHelper addValue:parsedObjects onObject:object forKeyPath:mapping.property]; + withPropertyName:[relationship property]]; + if(mapping.incrementalData) { + [EKPropertyHelper addValue:parsedObjects onObject:object forKeyPath:relationship.property]; } else { - [EKPropertyHelper setValue:parsedObjects onObject:object forKeyPath:mapping.property]; + [EKPropertyHelper setValue:parsedObjects onObject:object forKeyPath:relationship.property]; } } }]; @@ -109,13 +105,12 @@ - (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalR - (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping - incrementalData:(BOOL)incrementalData { NSMutableArray * array = [NSMutableArray array]; for (NSDictionary * representation in externalRepresentation) { - id parsedObject = [self objectFromExternalRepresentation:representation withMapping:mapping incrementalData:incrementalData]; + id parsedObject = [self objectFromExternalRepresentation:representation withMapping:mapping]; [array addObject:parsedObject]; } return [NSArray arrayWithArray:array]; @@ -124,7 +119,6 @@ - (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalReprese - (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping fetchRequest:(NSFetchRequest *)fetchRequest - incrementalData:(BOOL)incrementalData { NSAssert(mapping.primaryKey, @"A mapping with a primary key is required"); EKPropertyMapping * primaryKeyPropertyMapping = [mapping primaryKeyPropertyMapping]; @@ -148,7 +142,7 @@ - (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRep object = [NSEntityDescription insertNewObjectForEntityForName:mapping.entityName inManagedObjectContext:self.importer.context]; - [self fillObject:object fromExternalRepresentation:representation withMapping:mapping incrementalData:incrementalData]; + [self fillObject:object fromExternalRepresentation:representation withMapping:mapping]; [array addObject:object]; } @@ -170,17 +164,6 @@ - (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRep + (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping inManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self objectFromExternalRepresentation:externalRepresentation - withMapping:mapping - inManagedObjectContext:context - incrementalData:NO]; -} - -+ (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - inManagedObjectContext:(NSManagedObjectContext *)context - incrementalData:(BOOL)incrementalData { NSParameterAssert([mapping isKindOfClass:[EKManagedObjectMapping class]]); NSParameterAssert(context); @@ -189,27 +172,13 @@ + (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation externalRepresentation:externalRepresentation context:context]; return [[self mapperWithImporter:importer] objectFromExternalRepresentation:externalRepresentation - withMapping:mapping - incrementalData:incrementalData]; -} - -+ (id) fillObject:(id)object -fromExternalRepresentation:(NSDictionary *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - inManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self fillObject:object - fromExternalRepresentation:externalRepresentation - withMapping:mapping - inManagedObjectContext:context - incrementalData:NO]; + withMapping:mapping]; } + (id) fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping inManagedObjectContext:(NSManagedObjectContext*)context - incrementalData:(BOOL)incrementalData { NSParameterAssert([mapping isKindOfClass:[EKManagedObjectMapping class]]); NSParameterAssert(context); @@ -219,24 +188,12 @@ + (id) fillObject:(id)object context:context]; return [[self mapperWithImporter:importer] fillObject:object fromExternalRepresentation:externalRepresentation - withMapping:mapping - incrementalData:incrementalData]; -} - -+ (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - inManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self arrayOfObjectsFromExternalRepresentation:externalRepresentation - withMapping:mapping - inManagedObjectContext:context - incrementalData:NO]; + withMapping:mapping]; } + (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping inManagedObjectContext:(NSManagedObjectContext*)context - incrementalData:(BOOL)incrementalData { NSParameterAssert([mapping isKindOfClass:[EKManagedObjectMapping class]]); NSParameterAssert(context); @@ -246,27 +203,13 @@ + (NSArray *)arrayOfObjectsFromExternalRepresentation:(NSArray *)externalReprese context:context]; return [[self mapperWithImporter:importer] arrayOfObjectsFromExternalRepresentation:externalRepresentation - withMapping:mapping - incrementalData:incrementalData]; -} - -+ (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation - withMapping:(EKManagedObjectMapping *)mapping - fetchRequest:(NSFetchRequest *)fetchRequest - inManagedObjectContext:(NSManagedObjectContext *)context -{ - return [self syncArrayOfObjectsFromExternalRepresentation:externalRepresentation - withMapping:mapping - fetchRequest:fetchRequest - inManagedObjectContext:context - incrementalData:NO]; + withMapping:mapping]; } + (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRepresentation withMapping:(EKManagedObjectMapping *)mapping fetchRequest:(NSFetchRequest *)fetchRequest inManagedObjectContext:(NSManagedObjectContext *)context - incrementalData:(BOOL)incrementalData { NSParameterAssert([mapping isKindOfClass:[EKManagedObjectMapping class]]); NSParameterAssert(context); @@ -276,8 +219,7 @@ + (NSArray *)syncArrayOfObjectsFromExternalRepresentation:(NSArray *)externalRep context:context]; return [[self mapperWithImporter:importer] syncArrayOfObjectsFromExternalRepresentation:externalRepresentation withMapping:mapping - fetchRequest:fetchRequest - incrementalData:incrementalData]; + fetchRequest:fetchRequest]; } @end diff --git a/EasyMapping/EKMapper.h b/EasyMapping/EKMapper.h index 62ffbcc..5d5257c 100644 --- a/EasyMapping/EKMapper.h +++ b/EasyMapping/EKMapper.h @@ -56,24 +56,6 @@ fromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKObjectMapping *)mapping; -/** - Fills previously existed object with values, provided in JSON representation. All values, that are included in mapping and were filled prior to calling this method, will be overwritten. If incrementalData is true, to-many relationship data is pushed to the existing data instead of replaced. - - @param object Object to fill - - @param externalRepresentation JSON representation of object data - - @param mapping object mapping - - @param incrementalData Defines if to-many relationship data is pushed or replaced - - @result filled object - */ -+ (id) fillObject:(id)object - fromExternalRepresentation:(NSDictionary *)externalRepresentation - withMapping:(EKObjectMapping *)mapping - incrementalData:(BOOL)incrementalData; - /** Convenience method to create array of objects from JSON. diff --git a/EasyMapping/EKMapper.m b/EasyMapping/EKMapper.m index a8ba8e9..77c70e0 100644 --- a/EasyMapping/EKMapper.m +++ b/EasyMapping/EKMapper.m @@ -40,18 +40,11 @@ + (id)objectFromExternalRepresentation:(NSDictionary *)externalRepresentation wi } id object = [[mapping.objectClass alloc] init]; - return [self fillObject:object fromExternalRepresentation:externalRepresentation withMapping:mapping incrementalData:NO]; + return [self fillObject:object fromExternalRepresentation:externalRepresentation withMapping:mapping]; } + (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation withMapping:(EKObjectMapping *)mapping -{ - return [self fillObject:object fromExternalRepresentation:externalRepresentation withMapping:mapping incrementalData:NO]; -} - -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation - withMapping:(EKObjectMapping *)mapping - incrementalData:(BOOL)incrementalData { NSDictionary *representation = [EKPropertyHelper extractRootPathFromExternalRepresentation:externalRepresentation withMapping:mapping]; [mapping.propertyMappings enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { @@ -79,14 +72,14 @@ + (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalR id _value = [object valueForKeyPath:valueMapping.property]; - if(incrementalData && _value!=nil) { + if(mapping.incrementalData && _value!=nil) { _value = [_value arrayByAddingObjectsFromArray:parsedObjects]; [object setValue:_value forKey:valueMapping.property]; } else { [object setValue:parsedObjects forKeyPath:valueMapping.property]; } - } else if(!incrementalData) { + } else if(!mapping.incrementalData) { [object setValue:nil forKey:valueMapping.property]; } }]; diff --git a/EasyMapping/EKObjectMapping.h b/EasyMapping/EKObjectMapping.h index 2ce3839..e8f4289 100644 --- a/EasyMapping/EKObjectMapping.h +++ b/EasyMapping/EKObjectMapping.h @@ -31,6 +31,11 @@ @interface EKObjectMapping : NSObject +/** + Defines if to-many relationship data is pushed or replaced. + */ +@property (nonatomic, assign) BOOL incrementalData; + /** Class, for which this mapping is meant to be used. */ diff --git a/EasyMapping/EKPropertyHelper.m b/EasyMapping/EKPropertyHelper.m index baa4dc2..02f3754 100644 --- a/EasyMapping/EKPropertyHelper.m +++ b/EasyMapping/EKPropertyHelper.m @@ -147,7 +147,7 @@ +(void)addValue:(id)value onObject:(id)object forKeyPath:(NSString *)keyPath [self setValue:value onObject:object forKeyPath:keyPath]; } else { - if ([(id )object isKindOfClass:[NSManagedObject class]]) + if ([object isKindOfClass:[NSManagedObject class]]) { // Reducing update times in CoreData if(_value != value && ![value isSubsetOfSet:_value]) { diff --git a/EasyMappingExample/Tests/Specs/EKManagedObjectMapperSpec.m b/EasyMappingExample/Tests/Specs/EKManagedObjectMapperSpec.m index 9cfd284..05a0211 100644 --- a/EasyMappingExample/Tests/Specs/EKManagedObjectMapperSpec.m +++ b/EasyMappingExample/Tests/Specs/EKManagedObjectMapperSpec.m @@ -315,7 +315,11 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:YES]; + EKManagedObjectMapping * personMapping = [ManagedMappingProvider personMapping]; + personMapping.incrementalData = YES; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation + withMapping:personMapping + inManagedObjectContext:moc]; }); specify(^{ @@ -327,7 +331,7 @@ }); }); - context(@"with hasMany mapping and incremental data", ^{ + context(@"with hasMany mapping and no incremental data", ^{ __block NSManagedObjectContext* moc; __block ManagedPerson *person; @@ -335,10 +339,10 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:NO]; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithOtherPhones"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:NO]; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc]; }); @@ -359,10 +363,12 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:YES]; + EKManagedObjectMapping * personMapping = [ManagedMappingProvider personMapping]; + personMapping.incrementalData = YES; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:personMapping inManagedObjectContext:moc]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithOtherPhones"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:YES]; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:personMapping inManagedObjectContext:moc]; }); @@ -383,10 +389,10 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:NO]; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithZeroPhones"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:NO]; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc]; }); @@ -407,10 +413,12 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:NO]; + EKManagedObjectMapping * personMapping = [ManagedMappingProvider personMapping]; + personMapping.incrementalData = YES; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:personMapping inManagedObjectContext:moc]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithZeroPhones"]; - person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:[ManagedMappingProvider personMapping] inManagedObjectContext:moc incrementalData:YES]; + person = [EKManagedObjectMapper objectFromExternalRepresentation:externalRepresentation withMapping:personMapping inManagedObjectContext:moc]; }); diff --git a/EasyMappingExample/Tests/Specs/EKMapperSpec.m b/EasyMappingExample/Tests/Specs/EKMapperSpec.m index 2b6d9ca..be67f16 100644 --- a/EasyMappingExample/Tests/Specs/EKMapperSpec.m +++ b/EasyMappingExample/Tests/Specs/EKMapperSpec.m @@ -356,7 +356,7 @@ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; person = [EKMapper objectFromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping]]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithOtherPhones"]; - person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping] incrementalData:NO]; + person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping]]; }); specify(^{ @@ -379,7 +379,10 @@ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; person = [EKMapper objectFromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping]]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithOtherPhones"]; - person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping] incrementalData:YES]; + EKObjectMapping *mapping = [MappingProvider personMapping]; + mapping.incrementalData = YES; + person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation + withMapping:mapping]; }); specify(^{ @@ -402,7 +405,7 @@ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; person = [EKMapper objectFromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping]]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithZeroPhones"]; - person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping] incrementalData:NO]; + person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping]]; }); specify(^{ @@ -425,7 +428,9 @@ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; person = [EKMapper objectFromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping]]; externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithZeroPhones"]; - person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:[MappingProvider personMapping] incrementalData:YES]; + EKObjectMapping *personMapping = [MappingProvider personMapping]; + personMapping.incrementalData = YES; + person = [EKMapper fillObject:person fromExternalRepresentation:externalRepresentation withMapping:personMapping]; }); specify(^{