gpt4 book ai didi

objective-c - RestKit 0.20 映射问题

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:37 24 4
gpt4 key购买 nike

当我发出请求并尝试将响应放入 Core Data 时出现以下错误。

Performing managed object mapping with a nil managed object cache:
Unable to update existing object instances by identification attributes. Duplicate objects may be created.

我设置了 identifactionAttributes 并使用对象管理器来配置请求操作。而且我仍然收到“无法更新现有对象实例......”

objectMapping = [RKEntityMapping mappingForEntityForName:@"Entity"     inManagedObjectStore:self.managedObjectStore];
objectMapping.identificationAttributes = @[ @"route_id" ];
[objectMapping addAttributeMappingsFromDictionary:@{
@"point_alt" : @"point_alt",
@"point_lat" : @"point_lat",
@"point_long" : @"point_long",
@"location_id" : @"location_id",
@"route_id" : @"route_id"
}];


NSMutableURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:nil method:RKRequestMethodPOST path:path parameters:paramsWithEncr];

RKManagedObjectRequestOperation *operation = [[RKObjectManager sharedManager] managedObjectRequestOperationWithRequest:request managedObjectContext:self.managedObjectStore.mainQueueManagedObjectContext success:^(RKObjectRequestOperation *operation, RKMappingResult *result) {
NSLog(@"Loading mapping result: %d", result.count);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Fail!");
}];

最佳答案

我没有配置 Core Data 与对象管理器的集成。如果您遇到同样的问题,您应该这样做:

NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
NSString *path = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Store.sqlite"];
[managedObjectStore addSQLitePersistentStoreAtPath:path fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:nil];
[managedObjectStore createManagedObjectContexts];

关于objective-c - RestKit 0.20 映射问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13993149/

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