conorgriffin
conorgriffin

Reputation: 4339

How to serve data to an iPhone app for conversion to Core Data

I'm writing an iPhone app to display the location of items on Google Maps using MapKit. I have a set of items which are to be displayed on the map. These items can change over time so I'd like to manage them centrally on a webserver and allow the client to fetch it as new versions become available. There are a few ways I could do this and I'd like some input on my current ideas or suggestions for better alternatives.

Firstly, I want to use Core Data to store the items on the iPhone because I'm using this as a learning opportunity for Core Data as much as anything else. I would however like to hear thoughts on the server-side storage and formatting of the data for conversion by iOS to Core Data objects.

  1. Keep a flat XML file on the server containing all the items. Get the app to periodically check for new versions (I'll do a GET from the phone to check), when a new version is detected, I'll download the whole XML file (~1MB) and parse it using NSXMLParser and basically wipe the existing Core Data objects and populate the store with the new objects.
  2. Store the objects in a database on the server, serve them using PHP as an XML file. Have the app check periodically for new/updated entries and just fetch those, parse them and add to the store.
  3. Store the objects in a database on the server, serve them using JSON or some other format which would be better than the previous methods using XML and the NSXMLParser (I'm looking for suggestions in this area if there are better ways than XML etc.)

So, I'd like the solution to use Core Data on the phone, I understand NSXMLParser so I know how I can implement that solution really. I'd like to know if there are alternative ways of serving the data which reduces the amount of manipulation required to convert the server-side data to Core Data objects.

Upvotes: 1

Views: 355

Answers (1)

Max
Max

Reputation: 16719

First the server side: I have no doubts the you have to store you data in a database, because it's very flexible (you can provide your client with miscellaneous requests, you can add/update/change tables in your DB, while the external side remains the same).

As for the format of data, that you're sending from the server, I think that this the question of your own preferences and the problem domain. I prefer XML, but this is me. You can read this very nice article JSON vs XML If you choose JSON, then i suggest you this very nice utility framework for parsing it: json-framework

But your client should not care about the format of data. You have to define the interface with the constructor like

-(id) initWithDictionary:(NSDictionary*) dict;

no matter where did you get that dictionary (after parsing XML/JSON or from DB or whatever).

Upvotes: 1

Related Questions