2012-12-21 149 views
3

当我发出请求并尝试将响应放入核心数据时,出现以下错误。RestKit 0.20映射问题

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!"); 
    }]; 
+0

你收到的消息只是一个警告。你只是想摆脱警告?或者你有更大的问题?就像没有对象存储在数据库中一样? – plu

+0

没有对象存储在数据库中... –

回答

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