问题
i got into an issue with RKDynamicObjectMapping
, however it could be
that i misuse it.
I have the following scenario
- request to the service to get areas
- choose area
- request to the service to get journals for selected area
data returned by both calls looks like that
{ d: [{cutID:""}, {cutID:""}, {cutID:""}] }
{ d: [{journalID:""}, {journalID:""}, {journalID:""}] }
i have the following code
RKObjectMapping* cutMapping = [RKObjectMapping mappingForClass:[Cut
class]];
[cutMapping mapKeyPath:@"CutID" toAttribute:@"cutID"];
RKObjectMapping* journalMapping = [RKObjectMapping mappingForClass:
[Journal class]];
[journalMapping mapKeyPath:@"journalID" toAttribute:@"journalID"];
RKDynamicObjectMapping * dynamicMapping = [RKDynamicObjectMapping
dynamicMapping];
[dynamicMapping setObjectMapping:journalMapping
whenValueOfKeyPath:@"__metadata.type" isEqualTo:@"JournalDetails"];
[dynamicMapping setObjectMapping:cutMapping
whenValueOfKeyPath:@"__metadata.type" isEqualTo:@"Cut"];
[[[RKObjectManager sharedManager] mappingProvider]
setMapping:dynamicMapping forKeyPath:@"d"];
....
[objectManager loadObjectsAtResourcePath:getResourcePath
delegate:self];
....
and later
[objectManager loadObjectsAtResourcePath:getResourcePath
delegate:obj];
results of first request, which returns Cut
objects, is mapped flawlessly, but not for second which returns Journal
objects.
logging in request:didLoadResponse
showed that service returns
expected json , so the issue is with mappings
how to make it work with two mappings ?
Anyone using RestKit Dynamic Mapping yet ?
回答1:
I presume you've checked that your Cut object is mapping to a to-many relationship in the CoreData entity?
If so can you turn on the RESTKit logging and post the results
来源:https://stackoverflow.com/questions/8942696/restkit-rkdynamicobjectmapping-work-only-for-first-json-result