鉴于此 XML 有效负载:
<payload>
<year yearNum="2013">
<month monthNum="6" desc="This month was an enlightening month"/>
<month monthNum="5" desc="This month was a questioning month"/>
<month monthNum="4" desc="This month was a good month"/>
<month monthNum="3" desc="This month was a crazy month"/>
<month monthNum="2" desc="This month was a dry month"/>
<month monthNum="1" desc="This month was a slow month"/>
</year>
<year yearNum="2012">
<month monthNum="12" desc="This month was a cold month"/>
<month monthNum="11" desc="This month was an expensive month"/>
<month monthNum="10" desc="This month was a free month"/>
<month monthNum="9" desc="This month was a hard month"/>
<month monthNum="8" desc="This month was a surprising month"/>
<month monthNum="7" desc="This month was an energetic month"/>
<month monthNum="6" desc="This month was a hasty month"/>
<month monthNum="5" desc="This month was a relaxing month"/>
<month monthNum="4" desc="This month was a fair month"/>
<month monthNum="3" desc="This month was a strange month"/>
<month monthNum="2" desc="This month was a lucky month"/>
<month monthNum="1" desc="This month was a odd month"/>
</year>
</payload>
和一个映射:
RKEntityMapping *monthlyReportMapping =
[RKEntityMapping mappingForEntityForName:@"MonthlyReport"
inManagedObjectStore:[[RKObjectManager sharedManager] managedObjectStore]];
monthlyReportMapping.identificationAttributes = @[@"yearNumber", @"monthNumber"]];
[monthlyReportMapping addAttributeMappingsFromDictionary:@{
/*
* How would I set up the mappings for the yearNumber
* so I can use it as the composite identifier with
* the monthNumber? I want to do something like this:
*/
@"@metadata.parent.yearNum" : @"yearNumber",
@"monthNum" : @"monthNumber",
@"desc" : @"description"
}];
RKResponseDescriptor *monthlyMappingResponseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:monthlyReportMapping
pathPattern:@"/monthlyReports"
keyPath:@"payload.year.month"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:monthlyMappingResponseDescriptor];
当我在 keyPath 中映射时,您将如何访问yearNum
from ?monthlyReportMapping
payload.year.month
请假设我无法控制 XML 响应。
谢谢,贾斯汀