1
我遇到了映射嵌套对象值的问题。RestKit 0.20嵌套对象映射(对象树的路径不同)
我有两个对象具有以下属性: 一个)
class Input
@property NSString value;
@property NSString title;
B)
class Profile
@property Input myAwesomeInput;
..所以一个资料包含一个输入的对象。当我用RestKit(0.20)绘制对象时,我得到了某物。像这样:
{ myAwesomeInput_test:{"value":"xyz","title":"a title"}}
我想实现的是:
{myAwesomeInput_test:"xyz"}
所以我不想地图 “输入”,但只是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];
感谢,我想我们找到/张贴的答案在同一时间(看的时候公布。 – jeven 2013-05-10 17:40:15