2012-12-21 113 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];