iosrestkit-0.20

Response mapping to get object with dynamic path restkit


how to i set response mapping to manager with path pattern ..if the getobjects at path is different from path pattern that is used to map the response.

[manager addResponseDescriptorsFromArray:
@[[RKResponseDescriptor responseDescriptorWithMapping:categoryMapping
 pathPattern:A
 keyPath:nil
 statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]]];



[manager getObjectsAtPath:A/ID
 parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@" Category success");
[self.delegate didReceiveAssignedCategories];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Category failure");
}];

response mapping path ie:A must be set to dynamic path used to getobject ie:A/ID . ex:

Call 1)

A = /getAllCategories

A/ID = /getAllCategories/123

call 2)

A = /getAllCategories

A/ID = /getAllCategories/456

response mapping is same for 123, 456 only while getting the objects i am using different urls ie: with id's attached. how to do that ?


Solution

  • If you have 2 path patters which both return the same type of data then you can use the same mapping with 2 different response descriptors.

    If you have 1 path pattern which can return 2 different types of data then you need to use RKDynamicMapping to 'intercept' the incoming data and decide which mapping is actually required.


    From your edited question, 'pattern' is the important thing that you have misunderstood. You need to use a path pattern, not a static path:

    @"getAllCategories/:identity"