Skip to content

Instantly share code, notes, and snippets.

@holgersindbaek
Created January 30, 2013 13:29
Show Gist options
  • Save holgersindbaek/4673313 to your computer and use it in GitHub Desktop.
Save holgersindbaek/4673313 to your computer and use it in GitHub Desktop.
If I map this with only the issue mapping and leave out the article relationship, then everything is fine. If I include the article relationship, then I get the error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'RKManagedObjectMappingOperationDataSource must be initialized with a managed object context.'
//Setting up objectmapping for issue
RKObjectMapping *issueMapping = [RKObjectMapping mappingForClass:[Issue class]];
[issueMapping addAttributeMappingsFromDictionary:@{
@"title": @"title",
@"description": @"description",
@"cover_url": @"cover_url",
@"published_at": @"published_at",
@"issue_number": @"issue_number"
}];
//Setting up objectmapping for article
RKObjectMapping *articleMapping = [RKObjectMapping mappingForClass:[Article class]];
[articleMapping addAttributeMappingsFromDictionary:@{
@"title": @"title",
@"main_text": @"main_text",
@"article_image_url": @"article_image_url"
}];
[issueMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"articles" toKeyPath:@"articles" withMapping:articleMapping]];
Issue *issue = [Issue new];
RKMappingOperation *operation = [[RKMappingOperation alloc] initWithSourceObject:[parsedData objectForKey:@"issue"] destinationObject:issue mapping:issueMapping];
RKManagedObjectMappingOperationDataSource *dataSource = [RKManagedObjectMappingOperationDataSource new];
operation.dataSource = dataSource;
[operation start];
NSLog(@"Parse error: %@", parseError);
NSLog(@"Issue title: %@", issue.title);
@blakewatters
Copy link

Its hard for me to tell exactly what you are doing wrong here, but there are 2 possibilities:

  1. If your Issue and Article classes are backed by Core Data, then you need to use RKEntityMapping and call the designated initializer on RKManagedObjectMappingOperationDataSource -- i.e.
NSManagedObjectContext *context = [RKManagedObjectStore defaultStore].mainQueueManagedObjectContext;
RKFetchRequestManagedObjectCache *cache = [RKFetchRequestManagedObjectCache new];
RKManagedObjectMappingOperationDataSource *dataSource = [[RKManagedObjectMappingOperationDataSource alloc] initWithManagedObjectContext:context cache:cache];

or

  1. You are mapping to non-Core Data backed classes and using the wrong data source. Just replace your data source initialization with this:
RKObjectMappingOperationDataSource *dataSource = [RKObjectMappingOperationDataSource new];

@mourelatosm
Copy link

Hi Blake
I am having exactly the same issue.
Is there any recommended way to parse a local json string with RestKit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment