How do you handle web services in iOS? What about CoreData?

The web service sends data to the iOS client, and the client displays the data using a UITableView.

Data is usually a built-in whiteboard, a text list. It is sent from the web service via json format. (sometimes XML)

It does not need to be updated in real time, but I do not want to block the user interface due to the loading of the web service.

There are many ways to implement it, which one is right for you? 1 or 2.?

  • UITableViewController processes the json object.

    A simple way, but it can be difficult to encode.

  • Use CoreData as a local database.

    There's a local article repository, when json data comes from a web service, it updates the local CoreData repository. (download asynchronous web service)

    and the UITableViewController <> handles the update of the local CoreData repository and updates the UITableView with animation.

I think the second way is better to implement without spagenia code, but I'm afraid there is another performance problem, or is this not really stupid code?

Friends, how do you usually use a list of data from a web service?


Other comments:

I found a SeismicXML example from the Apple SDK, this is a well implemented example of method 1.

but I think it can be easily implemented using CoreData as a local repository.

  • Get data from a web service (async) and put the data in CoreData p>

  • The UITableViewController updates the UITableView in NSFetchedResultsControllerDelegate methods.

What do you think of this strategy?

+4
source share
2 answers

Check out RestKit . They have an example client for discussion forums for the iPhone, which receives data from the bulletin board server (also supplied in the example - built on rails) via json and saves it to the basic db data on the iphone. very elegant imo.

http://restkit.org/

+4
source

Option 1 is very simple if you use the JSON framework

Json framework

In your view controller, install it to download data from the server. Once the data has finished loading, use the JSON structure to populate your data model, and then call reload in the table to display the new data. Thus, there is no pause for the user during his download.

+1
source

All Articles