0

I'm developing an iPhone application (well, I'm migrating a Windows Phone 7.1 to iPhone), and I have some questions:

Previously, I've asked this question, Storing data in XML or SQL?, when I was developing a Windows Phone 7.1 app. And now I have the same question, but in this case it is about iPhone.

I've found in iOS development, that XML is not as easy to read as in Windows Phone. In this question, Reading XML attributes and text, you can find what method I'm using to read a XML file.

I'm sure, I don't need to use a database to store only 22 items, but, is there any other way to store that 22 items? Or, maybe, you know an easy way to read XML.

I need something like this:

<?xml version="1.0" encoding="utf-8" ?>
<cards>
  <card id ="0">
    <name lang="en">Mad</name>
    <description lang="en">This...</description>
  </card>
...
</cards>

This data will be readonly: user will never change it. And it will be as file bundled with my app.

Community
  • 1
  • 1
VansFannel
  • 45,055
  • 107
  • 359
  • 626
  • I am using Core Data for all data with more than 20 items. If you only have to store 22 items you could also use a singleton and an array. To store this array you could use NSUserDefaults. – dasdom Dec 12 '11 at 17:35

4 Answers4

0

XML Parsing in Objective C isn't that challenging. Please see this example on Introduction to Tree-Based XML Programming Guide for Cocoa http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html#//apple_ref/doc/uid/TP40001263-SW1

Santosh
  • 328
  • 5
  • 9
0

I'm going ahead and using Core Data in my project even though I don't really have all that much to store. It's really not all that difficult, especially since you can choose Core Data as an option in a couple of the Apple templates. Inside the iOS developer library they also have a pretty good basic tutorial.

Core Data Starting Point

I guess the main difference between whether I would use the Plist or Core Data would be whether I expect my data to be static from compile time or to be updated by the user.

Shea Daniels
  • 3,232
  • 3
  • 23
  • 27
0

You haven't said how you are using this data.

Are you talking about simply bundling data with your application? If so, the simplest way of doing so is to use a property list (plist). Both NSArray and NSDictionary have convenience methods to pull arrays and dictionaries straight out of plists, and there is a graphical editor build into Xcode.

Are you loading this data over a web service? Do you have to support multiple platforms? If this is the case, then JSON would be a better option. JSON support was only included in iOS 5, but if you need to support earlier versions, JSONKit will handle this for you.

Do you have to update and run queries over the data? Core Data is a better option for this kind of thing. You can preload it with the contents of a plist or JSON file when the user first runs the application.

There are a lot of different options, and unless you provide more detail, it's difficult to give you good advice.

Jim
  • 72,985
  • 14
  • 101
  • 108
-1

Plist files

Documentation: http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html

Example: http://www.ifans.com/forums/showthread.php?t=64679

LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • Thanks for your answer. I've never worked with Plist files. How can I represent my XML structure in a plist file? – VansFannel Dec 12 '11 at 17:51