簡體   English   中英

RestKit核心數據“ managedObjectStore為零”

[英]RestKit Core Data 'managedObjectStore is nil'

我不知道這是否是造成問題的根本原因,但是在使用

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

它可以完成一些工作,並且在嘗試映射響應時會出現以下警告:

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

其次是:

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

我認為這是因為它與托管對象映射不匹配我的請求,但是我不知道為什么。 我正在使用以下代碼創建持久存儲:

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

適當的映射/響應描述符:

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

似乎您沒有使用對托管對象存儲的引用來配置對象管理器。 創建對象管理器時,應該這樣做:

objectManager.managedObjectStore = managedObjectStore;

如果沒有此工具,則RestKit將退回到對所有內容使用純對象操作的狀態。

注意:如果您正在記錄警告,則會看到“ 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