I am migrating my connection classes to support Caching via CoreData. RestKit does it automagically using RKEntityMapping. RestKit and CoreData did the mapping and validation correctly, I got a bunch of NSManagedObject I requested for but it is not saving the objects to the CoreData. When I check the logs, I got this.
W restkit.network.core_data:RKManagedObjectRequestOperation.m:776 Saving of managed object context failed, but a `nil` value for the `error` argument was returned. This typically indicates an invalid implementation of a key-value validation method exists within your model. This violation of the API contract may result in the save operation being mis-interpretted by callers that rely on the availability of the error.
E restkit.network.core_data:RKManagedObjectRequestOperation.m:818 Failed saving managed object context to the persistent store <NSManagedObjectContext: 0x145e5ce0>: (null)
I don't have an idea, why is this occurring. I checked my Model for wrong settings or attributes but I can't find any. As I observed, NSManagedObjects is saved InMemory (NSFetchResultsController was still able to fetch the objects even when I leave the view. So I guess, the objects were saved InMemory). Can someone help me find what is wrong here. Leaving any tips for debugging the problem is welcome. Thank you.
I had this code to setup the core data.
- (void)setupCoreData
{
NSManagedObjectModel *managedObjectModel = [[AppDelegate sharedDelegate] managedObjectModel];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
[[RKObjectManager sharedManager] setManagedObjectStore:managedObjectStore];
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Model.sqlite"];
NSError *error;
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:@{NSMigratePersistentStoresAutomaticallyOption:@YES, NSInferMappingModelAutomaticallyOption:@YES} error:&error];
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);
// Create the managed object contexts
[managedObjectStore createManagedObjectContexts];
// Configure a managed object cache to ensure we do not create duplicate objects
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
}
This is called before I add all response/request descriptors. I generated the model class using MoGenerator. I override some setters and did some validations before inserting (validateForInsert).