RestKit mapping: how to GET multiple root objects
ios, restkit
Solution
Yes, RestKit can do that. You need:
- 2 object mappings, 1 linking to `Article` and the other to `NSMutableDictionary`
- 2 response descriptors, 1 with keypath `articles` and the other `counters_for_pagination`
Once you have that setup, the mapping result dictionary will contain 2 keys which match the key paths in your response descriptors so that you can access your 2 different types of information.
(in effect, the mapping results is your intermediate class)
Problem
I need to GET multiple root objects with RestKit. JSON from server looks like this: ``` { "articles" : [{...}, {...}, {...}, {...}, {...}], "counters_for_pagination": {"page": 1, "total": 250, "per_page": 5} } ``` Do I have to create intermediate class `PaginatedResults` which will hold `NSArray` of objects of type `Article` and `NSDictionary` with counters? I'd like to get: - an array of `Article` objects which I will show in a `UITableView` - an `NSDictionary` of counters - for pagination. Is RestKit able to return `NSDictionary` of 2 different objects as a `*result` or is it always returning an array?