Good afternoon everyone,
Currently, my REST API returns the JSON in the form {“meta”:{}, “objects”:{}}. (This is done using TastyPie). I would like back in iOS, to grab only the objects. Before I was using the line:
[omp setMapping:userMapping forKeyPath:@"objects"];
and it was working great. Now however, I have added quite a few more Mappings and I ended up doing something like this:
RKObjectMappingProvider *omp = [[RKObjectManager sharedManager] mappingProvider];
RKObjectMapping *cellMapping = [Cell mapping];
[omp addObjectMapping:cellMapping];
[omp setObjectMapping:cellMapping forResourcePathPattern:@"/cells/?format=json"];
[cellMapping setRootKeyPath:@"objects"];
RKObjectMapping *userMapping = [User mapping];
[omp addObjectMapping:userMapping];
[omp setObjectMapping:userMapping forResourcePathPattern:@"/users/?format=json"];
[omp setMapping:userMapping forKeyPath:@"objects"];
I have been using this http://kalapun.com/blog/2012/05/17/how-i-restkit/. But as you can guess, this won’t work if I load a Cell and try to get its properties, because “User” took the “Objects” mapping. Can I combine both of these fields forResourcePathPattern and forKeyPath?!
Also, what is the purpose of doing SetObjectMapping after AddObjectMapping? Do I need both?!
Thanks!
Fixed in RestKit 0.2! We will be able to directly insert a KeyPath, which is awesome!