Skip to content

Instantly share code, notes, and snippets.

@tanis2000
Created April 24, 2014 15:12
Show Gist options
  • Save tanis2000/11258321 to your computer and use it in GitHub Desktop.
Save tanis2000/11258321 to your computer and use it in GitHub Desktop.
NSMutableDictionary *mappingsDictionary = [[NSMutableDictionary alloc] init];
// Add DailyGoalDetails->MGRDailyGoalDetail mapping
[mappingsDictionary setObject:[MGRDailyGoalDetail responseMapping] forKey:@"DailyGoalDetails"];
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithRepresentation:parsedData mappingsDictionary:mappingsDictionary];
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:[MGRModel sharedModel].managedObjectStore.persistentStoreManagedObjectContext cache:[MGRModel sharedModel].managedObjectStore.managedObjectCache];
dataSource.parentOperation = mapper;
mapper.mappingOperationDataSource = dataSource;
NSError *mappingError = nil;
BOOL isMapped = [mapper execute:&mappingError];
if (isMapped && !mappingError) {
NSLog(@"[postJsonGzippedAsData] jsonMappingResult = %@",[mapper mappingResult]);
[[[[MGRModel sharedModel] managedObjectStore] persistentStoreManagedObjectContext] save:&mappingError];
}
mappingsDictionary = [[NSMutableDictionary alloc] init];
// Add UserSessions->MGRSession mapping
[mappingsDictionary setObject:[MGRSession responseMapping] forKey:@"UserSessions"];
mapper = [[RKMapperOperation alloc] initWithRepresentation:parsedData mappingsDictionary:mappingsDictionary];
dataSource.parentOperation = mapper;
mapper.mappingOperationDataSource = dataSource;
mappingError = nil;
isMapped = [mapper execute:&mappingError];
if (isMapped && !mappingError) {
NSLog(@"[postJsonGzippedAsData] jsonMappingResult = %@",[mapper mappingResult]);
[[[[MGRModel sharedModel] managedObjectStore] persistentStoreManagedObjectContext] save:&mappingError];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment