Question

I don't know if this is the root cause of my issue or not, but when making my request using

appropriateObjectRequestOperationWithObject:nil method:RKRequestMethodGET path:path parameters:nil

it does some work, and when trying to map the response gives me this warning:

W restkit:RKObjectManager.m:635 Asked to create an `RKManagedObjectRequestOperation` object, but managedObjectStore is nil.

followed by:

CoreData: error: Failed to call designated initializer on NSManagedObject class 'Container'

I assume that this is because it is not matching my request against a Managed Object Mapping, but I can't figure out why. I am creating a persistent store using this code:

// Initialize managed object store
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
NSError *error = nil;
[managedObjectStore createPersistentStoreCoordinator];
BOOL success = RKEnsureDirectoryExistsAtPath(RKApplicationDataDirectory(), &error);
if (! success) {
    RKLogError(@"Failed to create Application Data Directory at path '%@': %@", RKApplicationDataDirectory(), error);
}
NSString *path = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Store.sqlite"];
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:path fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:&error];
if (! persistentStore) {
    RKLogError(@"Failed adding persistent store at path '%@': %@", path, error);
}
[managedObjectStore createManagedObjectContexts];

The appropriate mapping/response descriptor:

RKEntityMapping *containerMapping = [RKEntityMapping mappingForEntityForName:@"Container" inManagedObjectStore:managedObjectStore];
[containerMapping addAttributeMappingsFromDictionary:@{
                                                  @"id" : @"containerId",
                                                  @"name" : @"name",
                                                  @"public" : @"isPublic",
                                                  @"user": @"userId",
                                                  }];
containerMapping.identificationAttributes = @[@"containerId"];

responseDescriptor = [RKResponseDescriptor 
    responseDescriptorWithMapping:containerMapping
    method:RKRequestMethodAny
    pathPattern:nil 
    keyPath:@"containers"
    statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
Was it helpful?

Solution

It seems that you have not configured the object manager with a reference to the managed object store. This should be done when you create the object manager:

objectManager.managedObjectStore = managedObjectStore;

without this RestKit falls back to using plain object operations for everything.

Note: If you're logging warnings you would see Asked to create an RKManagedObjectRequestOperation object, but managedObjectStore is nil in the log output.

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