I am changing my app from using a purely remote DB to pulling the remote DB into a local DB. I am getting this Error when I am trying to get an Array of Objects from the remote database.
CoreData: error: Failed to call designated initializer on NSManagedObject class 'Class'
I am not sure what I am doing wrong. Here is my restkit setup.
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://fake.herokuapp.com"]];
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"App" withExtension:@"momd"];
NSManagedObjectModel *managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
manager.managedObjectStore = managedObjectStore;
RKEntityMapping *classMapping = [RKEntityMapping mappingForEntityForName:@"Class" inManagedObjectStore:managedObjectStore];
[classMapping addAttributeMappingsFromDictionary:[Class propertyMappings]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *classDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:classMapping pathPattern:@"/class.json" keyPath:@"" statusCodes:statusCodes];
[manager addResponseDescriptorsFromArray:@[classDescriptor]];
[managedObjectStore createManagedObjectContexts];
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
[RKObjectManager setSharedManager:manager];
And here is the request I am making, where it fails ( i think on the response).
[manager getObjectsAtPath:@"class.json" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
NSLog(@"Success");
}failure:^(RKObjectRequestOperation *operation, NSError *error) {}];
If you need anything else just let me know.
And if you could help out I will be a very happy developer.
Thank you,
-DO
EDIT
This is what propertMappings returns
+ (NSDictionary *) propertyMappings{return @{@"id" : @"iD", @"name" : @"name", @"image_url" : @"image_url"};}
Well the problem was actually that the Entity I was trying to pull in was nested through a few relationships in my model so it wasn’t the parent. It was causing an error. I had to adjust my api a little bit and everything worked.
Thanks for your help.
-DO