1

ネストされたオブジェクト値のマッピングで問題が発生しました。

次のプロパティを持つ 2 つのオブジェクトを取得しました。

class Input
@property NSString value;
@property NSString title;

b)

class Profile
@property Input myAwesomeInput;

..プロファイルには入力オブジェクトが含まれています。RestKit (0.20) でオブジェクトをマップすると、sth が得られます。このような:

{ myAwesomeInput_test:{"value":"xyz","title":"a title"}}

私が達成したいのは:

{myAwesomeInput_test:"xyz"}

したがって、「Input」をマップするのではなく、Input.value だけをマップします。それは可能ですか?

現時点では、私のコードは次のようになります。

RKObjectMapping* inputMapping = [RKObjectMapping requestMapping];
[inputMapping addAttributeMappingsFromArray:@[@"value"]];

RKRequestDescriptor *reqDescInput = [RKRequestDescriptor requestDescriptorWithMapping:inputMapping objectClass:[Input class] rootKeyPath:nil];

RKObjectMapping* searchProfile = [RKObjectMapping requestMapping];
RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];

[searchProfile addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"myAwesomeInput" toKeyPath:@"myAwesomeInput_test" withMapping:inputMapping]];

編集:(解決済み)

わかりました私はそれを解決しました。それが人々が行うべき方法であることを願っています。辞書内から直接アドレス指定できます。

RKObjectMapping* searchProfile =  [RKObjectMapping requestMapping];
[aeSearchProfile addAttributeMappingsFromDictionary:@{
        @"myAwesomeInput.value": @"myAwesomeInput_test"
}];

RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];
4

1 に答える 1

3

複数のマッピングではなくキーパスを使用します。これを試して:

RKObjectMapping* searchProfile = [RKObjectMapping requestMapping];
[searchProfile addAttributeMappingsFromDictionary:@{ @"myAwesomeInput.value" : @"myAwesomeInput_test" }];

RKRequestDescriptor *reqDescSearchProfile = [RKRequestDescriptor requestDescriptorWithMapping:searchProfile objectClass:[SearchProfile class] rootKeyPath:nil];
于 2013-05-10T16:59:14.223 に答える