iosobjective-crestkit

Using Multiple Base URLs and Multiple Object Managers (RestKit)


I'm trying to use two API's in an iOS app.

I'm using RestKit and following their guide per this article: https://github.com/RestKit/RestKit/wiki/Using-Multiple-Base-URLs-(and-Multiple-Object-Managers)

What do I do instead of the retain in this code since its no longer an option?

AppDelegate.m

RKObjectManager *flickrManager = 
        [RKObjectManager objectManagerWithBaseURL:flickrBaseUrl]; // <-- shared singleton
RKObjectManager *foursquareManager = 
        [[RKObjectManager objectManagerWithBaseURL:foursquareBaseUrl] retain]; // <-- you must retain every other instance.

Solution

  • You want to store all of the object managers somewhere. If using ARC you don't retain, you want to store in an array / dictionary (key with the URL perhaps) / properties (strong).

    In the example code you show, the first object manager isn't retained because RestKit holds one reference for you (the singleton). Generally, when using multiple object managers you want to ignore the singleton storage and manage all of the object manager references yourself.

    I would recommend using a data controller which hides the object manager properties internally and instead exposes an API based on your data model objects. Internally, it can choose the appropriate object manager for each request it receives.