开发者

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

Web service sends data to iOS client, and client shows data with UITableView.

Data is usually article of built-in board, text list. It is sent from web service via json format. (sometimes XML)

It doesn't need to be updated in real-time, but I don't want to block UI due to loading of web service.

There's man开发者_JS百科y ways to implement it, which way do you proper? 1. or 2. ?

  1. UITableViewController handles json object.

    Simple way, but it can be complicated to coding up.

  2. Use CoreData as local database.

    There's local repository for articles, when json data is came from web service, it updates local CoreData repository. (async web service load)

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

I think second way is better to implement without spaghetii code, but I'm afraid there's other performance issue, or isn't it totally stupid code?

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


More comments:

I found SeismicXML example from Apple SDK, it is well-implemented example of way 1.

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

  1. Get data from web service (async), and put data into CoreData

  2. UITableViewController updates UITableView in NSFetchedResultsControllerDelegate methods.

How do you think of this strategy?


Check out RestKit. They have an example of a discussion board client for iPhone that gets it's data from a discussion board server (also supplied in the example - built on rails) via json and stores it to core data db on the iphone. very elegant imo.

http://restkit.org/


Option 1 is very simple if you use the JSON framework

JSON Framework

In your view controller, set it downloading the data from the server. Once the data has finished downloading, use the JSON framework to populate your data model and then call reload on the table to display the new data. That way there is no pause for the user while it is downloading it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜