0
如何映射同一類型的嵌套對象? 我有一個XML與可以包含相同類型的多個對象的對象:RestKit ios嵌套同一類型的對象
<entry location="l1">
<entry location="l1.1">
<entry location="l1.1.1">
</entry>
<entry location="l1.1.2">
</entry>
</entry>
</entry>
我得到一個無限遞歸如果我添加propertymapping用相同的映射:
+ (RKObjectMapping *)objectMapping {
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]];
[mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}];
[mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"nextEntries"
toKeyPath:@"entries"
withMapping:[Entry objectMapping]]];
return mapping;
}
是有可能將子對象添加到每個父對象的數組中?
歡呼
//編輯:下面的代碼工作對我來說:
+ (RKObjectMapping *)objectMapping
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]];
[mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}];
RKObjectMapping *innerMapping = [RKObjectMapping mappingForClass:[Entry class]];
[innerMapping addAttributeMappingsFromDictionary:@{@"location": @"location"}];
[mapping addPropertyMapping:[RKRelationshipMapping
relationshipMappingFromKeyPath:@"entry"
toKeyPath:@"entries"
withMapping:innerMapping]];
return mapping;
}
非常感謝,它的作品! – kampfgnu
請接受正確的答案/幫助您解決問題。謝謝 :) – Wain