There might be cases when you need to make your own custom logic for a specific mapping. One of the possible ways of doing this is to define mapping to a setter, where you will process the response dictionary yourself.
For our example, as MongoDB saves the id
of a document in its body. We will use such techniques to extract the id
attribute from the body. First, let's look at the mapping configuration:
Class itemClass = [MDocument class]; RKObjectMapping *mapping = [RKObjectMapping mappingForClass:itemClass]; [mapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"rootDocument"] ];
Now, rootDocument
in our MDocument
class is just a property with a custom setter (or you can create a custom setter method that accepts additional arguments, in case you consider that using properties for this is not the best practice):
// In @interface MDocument // The fake setter @property (nonatomic, assign...