Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestKit mapping: how to GET multiple root objects

Tags:

ios

restkit

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:

  1. an array of Article objects which I will show in a UITableView
  2. 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?

like image 380
Roman Avatar asked Nov 18 '25 16:11

Roman


1 Answers

Yes, RestKit can do that. You need:

  1. 2 object mappings, 1 linking to Article and the other to NSMutableDictionary
  2. 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)

like image 135
Wain Avatar answered Nov 20 '25 07:11

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!