views:

514

answers:

1

Hi,

I am a beginner to iPhone App development. Please help me out.

In my iPhone application, I am making an API request and getting an XML.

I have to parse it, store it in a object(or xml as such) and also display it in my application at a later point of time (Its more like storing the current state).

I figured out how to request API, parse it, but dono what to do for storing it. Here are my constraints.

  1. When I exit & re-open the application next time, I have to retain the downloaded XML data.
  2. I have explored and got solutions to request API and parsing it using NSXMLParser. But for storing it in phone memory or application bundle, I have not got a clear idea.
  3. As I searched through various threads & blogs for storing the data, I get to know about several ways to do this.

    a. Saving NSDefaults

    b. SQLite Database

    c. Storing it as plist

    b. Core data

I am not sure on any of the above. Please let me know on which is the best way (should be none of the above i guess - ;) ) to store the XML data for later use along with the time, so that I can check it and update it on later stage.

Thanks in advance

A: 

You could implement your parser so that it creates and populates Core-Data NSManagedObjects. These can then be persisted to data store quite simply and can be used by other layers in your app - such as the view - as you would normal objects.

Core-Data can persist these managed objects to a number of different data store types - including SQLite. Once persisted the application can load the data from the Core-Data data store instead of re-parsing the XML.

I have successfully implemented a similar solution myself and would recommend reading Apple's Core Data Tutorial to get you started.

teabot
Thanks for your immediate response! I finalized this thing at last... :)I still have one question in my mind.. What actually the NSUserDefaults used for? I couldn't be clear on that. I guess you can make me clear on this..Thanks
techastute