【问题标题】:RestKit 0.20 Mapping problemsRestKit 0.20 映射问题
【发布时间】:2012-12-21 15:50:36
【问题描述】:

我在发出请求并尝试将响应放入 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!");
    }];

【问题讨论】:

  • 您收到的消息只是一个警告。你只是想摆脱警告吗?还是你有一些更大的问题?好像根本没有对象存储在数据库中?
  • 数据库中没有存储对象...

标签: objective-c xcode http core-data restkit


【解决方案1】:

我没有配置核心数据与对象管理器的集成。如果你有同样的问题,你应该这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    • 2012-12-25
    相关资源
    最近更新 更多