简体   繁体   English

RestKit核心数据“ managedObjectStore为零”

[英]RestKit Core Data 'managedObjectStore is nil'

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)];

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. 如果没有此工具,则RestKit将退回到对所有内容使用纯对象操作的状态。

Note: If you're logging warnings you would see Asked to create an RKManagedObjectRequestOperation object, but managedObjectStore is nil in the log output. 注意:如果您正在记录警告,则会看到“ Asked to create an RKManagedObjectRequestOperation object, but managedObjectStore is nil在日志输出中Asked to create an RKManagedObjectRequestOperation object, but managedObjectStore is nil

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM