0

I have an array with close to 1000 instances of a class, each of which has about 5 short strings (<100 chars) associated to it. In my app, I randomly select an object from the array frequently, and rarely but occasionally list all of the objects in the array.

My inclination is to use a .plist to store the data, so that it is all read in at the start, but is this really better than using SQLite in this case?

Right now, the array is static, though I may want to add the ability to add objects in the future. This would only happen occasionally, though.

PengOne
  • 48,188
  • 17
  • 130
  • 149

4 Answers4

0

How about using XMLSerialisation?

Raj
  • 1,742
  • 1
  • 12
  • 17
  • I'm not familiar with that. Do you happen to know what the benefits/disadvantages are compares with using a property list file or sqlite database? – PengOne Dec 19 '10 at 18:17
0

You could take a few routes. The easiest would be to simply write out the array to the user's documents directory. Look at NSArray, in particular - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag. You can find many insights in Apple's Archives and Serializations Programming Guide: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Archiving/Archiving.html%23//apple_ref/doc/uid/10000047i

However, there is a lot to be gained by using CoreData, too. It may be worth your while to at least scrape the surface and see if the benefits outweigh the implementation time.

joshpaul
  • 953
  • 8
  • 12
  • I think this is way more sophisticated than what I need for this project, but certainly something to keep in mind for future reference. Thanks! – PengOne Dec 19 '10 at 20:39
0

I'd recommend you also look into JSON formatting. http://code.google.com/p/json-framework/

Tim
  • 5,371
  • 3
  • 32
  • 41
  • Along these lines I'd suggest taking a look at [this question](http://stackoverflow.com/questions/2256625/comparison-of-json-parser-for-objective-c-json-framework-yajl-touchjson-etc), which is a comparison of the various iPhone JSON libraries. – johne Dec 20 '10 at 12:32
  • @johne: Thanks for the link to that vortex. – Tim Dec 20 '10 at 13:29
0

I think I interpretted this question differently than everyone else so far. To me, it sounds like he has the data when he is building the application and wants to know the best way to load it. The answers given so far are about how to save it from the running app.

For that much data, using SQLite would be faster, especially when you only need a random object. However, using a plist is easier to implement and edit.

ughoavgfhw
  • 39,734
  • 6
  • 101
  • 123
  • Yes, I already have the data and it doesn't change (not yet, anyway) so I just need the best way to load it. I need a random object about every 10 seconds and I was lazy, so I went with plist. I'll try SQLite though and see if it speeds things up. Thanks! – PengOne Dec 19 '10 at 20:38