Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestKit Conditional Mapping

I have a Media model, and Image,Video and Audio models that inherit from media. I am using RestKit to map the data from an API(rails app).

Is there a way to do a conditional mapping using RestKit? If my response contains a media_type of video, then use the Video model mapping otherwise the image mapping etc.

Update

RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
RKObjectMapping *videoMapping = [RKObjectMapping mappingForClass:[MMXMediaVideo class]];
RKObjectMapping *imageMapping = [RKObjectMapping mappingForClass:[MMXMediaImage class]];
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"medium_type" expectedValue:@"video" objectMapping: videoMapping]];
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"medium_type" expectedValue:@"image" objectMapping:imageMapping]];

How do I add a mapping method to video or image mapping?

like image 837
ShivamD Avatar asked Sep 03 '26 13:09

ShivamD


1 Answers

You configure your response descriptor with a dynamic mapping (RKDynamicMapping). This mapping checks the incoming data to decide which mapping is the appropriate one to apply and returns that. The returned mapping is then used to perform the actual destination object creation and run the mapping procedure.

like image 198
Wain Avatar answered Sep 06 '26 03:09

Wain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!