2017-01-22 1 views
0

イムにnilを設定する:逃した要素のデフォルト値を無視する代わりに、特定のフィールドせずに応答を送信しようとしている、とRestKitはまだnilを私は使用してこのオプションを無効にしているためにも、後の値を設定し続けるRestKit

infoMapping.assignsDefaultValueForMissingAttributes = NO; 

完全なマッピングコード:

RKEntityMapping *infoMapping = [RKEntityMapping mappingForEntityForName:@"IndexInfo" inManagedObjectStore:managedObjectStore]; 
    //userMapping.identificationAttributes = @[@"id"]; 
    [infoMapping addAttributeMappingsFromDictionary:@{ 
                 @"first" : @"first", 
                 @"last" : @"last" 
                 }]; 

    infoMapping.assignsDefaultValueForMissingAttributes = NO; 

RKResponseDescriptor *infoResponseDescriptor = 
    [RKResponseDescriptor responseDescriptorWithMapping:infoMapping 
               method:RKRequestMethodGET 
              pathPattern:@"/core/feed.json" 
               keyPath:@"info" 
              statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful) 

私は本当にこれはバグがある場合は、手動でそれを無効にするには、マッピングをフックするために、その周りに他の方法があり、部分的なデータで応答できるようにする必要がありますか?

答えて

0

私のinfoMappingのたびに新しいエンティティが作成されていました。

回避策ivには応答にid属性が含まれ、この追加がマップされ、それをID属性として使用しました。これはおそらく最良の解決策ではありませんが、今のところうまくいきます。 (私のIDは私の応答では常に0なので)

また、私のIndexInfoモデルにいくつかのバリデーションが含まれています。

infoMapping.identificationAttributes = @[@"id"]; 
    [infoMapping addAttributeMappingsFromDictionary:@{ 
                 @"id" : @"id", 
                 @"first" : @"first", 
                 @"last" : @"last" 
                 }]; 

検証:私も必要

- (BOOL)validateFirst:(id *)ioValue error:(NSError **)outError { .... 

infoMapping.performsKeyValueValidation = YES; 
infoMapping.discardsInvalidObjectsOnInsert = YES; 

代わり

// infoMapping.assignsDefaultValueForMissingAttributes = NO; 

のIDがこれまで以上に把握I'lように使用されていませんエレガントな方法と更新の答え。

関連する問題