我正在将我的应用程序从使用纯远程数据库更改为将远程数据库拉入本地数据库。当我尝试从远程数据库获取对象数组时出现此错误。
CoreData: error: Failed to call designated initializer on NSManagedObject class 'Class'
我不确定我做错了什么。这是我的restkit设置。
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];
这是我正在提出的请求,但它失败了(我认为是响应)。
[manager getObjectsAtPath:@"class.json" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){
NSLog(@"Success");
}failure:^(RKObjectRequestOperation *operation, NSError *error) {}];
如果您需要其他任何东西,请告诉我。如果你能帮忙,我会是一个非常快乐的开发者。
谢谢,
-做
编辑
这是propertMappings 返回的
+ (NSDictionary *) propertyMappings{return @{@"id" : @"iD", @"name" : @"name", @"image_url" : @"image_url"};}