Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your web service happens to be a Ruby on Rails application, then Objective Resource is a great tool: <a href="http://iphoneonrails.com/" rel="nofollow noreferrer">http://iphoneonrails.com/</a>.</p> <p>If not, then what I tend to do is use ASIHTTPRequest (<a href="http://allseeing-i.com/ASIHTTPRequest/" rel="nofollow noreferrer">http://allseeing-i.com/ASIHTTPRequest/</a>) which provides a nice network layer. Depending on the API, you might use ASI objects directly, or else you can subclass an existing ASI class if you want to add per-request functionality (such as authentication or response parsing).</p> <p>You usually want to run requests in the background, so that the UI isn't blocked while waiting for the request to finish. You can always go the background thread route, but a nice "Objective C" style approach that ASIHTTPRequest provides is to instead provide a delegate which is called when the request finishes (see also "Creating an asynchronous request" at <a href="http://allseeing-i.com/ASIHTTPRequest/How-to-use" rel="nofollow noreferrer">http://allseeing-i.com/ASIHTTPRequest/How-to-use</a>). In many cases the request delegate is the view controller that initiates the request.</p> <p>The model layer depends on the complexity, and also what format the data comes in. Most of the APIs I've worked with use JSON, for which you can use SBJSON or yajl-objc to parse. These usually give you the data parsed into base classes like NSString, NSArray and NSDictionary. Sometimes that's sufficient, or if you want your models to exist as their own classes, then you can have the models inherit from a base class that takes care of turning the NSDictionary/NSArray into properties.</p> <p>Finally for caching, Core Data provides a good way to persist to disk. For caching in memory, you can have the requests occur in a separate "manager" class that is shared between controllers. These managers use the Singleton design pattern as described here: <a href="https://stackoverflow.com/questions/145154/what-does-your-objective-c-singleton-look-like">What should my Objective-C singleton look like?</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload