Question

I've managed to successfully manually map a json string with a managed object, but I just can't find how to have the result object inserted into a managed object context of my choice. Do I have to create an instance of RKObjectManager to do that ?

NSMutableDictionary *area = [NSMutableDictionary dictionaryWithObject:dictionary forKey:@"restricted_position_detail"];
NSString* JSONString = [[DataProviderManager sharedManager] getJsonStringFromObject:area];
NSString* MIMEType = @"application/json";
NSError* error = nil;
id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType:MIMEType];
id parsedData = [parser objectFromString:JSONString error:&error];
if (parsedData == nil && error) {
    DLog(@"%@",error);
}

RKObjectMappingProvider* mappingProvider = [RKObjectManager sharedManager].mappingProvider;
[mappingProvider setMapping:[self getObjectMapping] forKeyPath:@"restricted_position_detail"];
RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
RKObjectMappingResult* result = [mapper performMapping];
if (result) {
    DLog(@"Yay! Mapping finished successfully");
}
else{
    DLog(@"Yay! Mapping failed");
}
Was it helpful?

Solution

Finally all I had to do was setting the RKObjectMapper instance targetObject property to an object created in the good moc !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top