gpt4 book ai didi

ios - RestKit核心数据“managedObjectStore为零”

转载 作者:行者123 更新时间:2023-12-01 18:14:57 25 4
gpt4 key购买 nike

我不知道这是否是造成问题的根本原因,但是在使用

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

关于ios - RestKit核心数据“managedObjectStore为零”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22898653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com