views:

113

answers:

2

I'm developing an iPad application and I'm not sure what's the best way to store application data. So far I've been using a .plist that stores hundreds of strings for a puzzle game and that works great, but if my app is to be any good, it's going to have to store tens of thousands of strings (representing pre-made puzzles).

I've read that it's a bad idea to use .plist for large files, so what is the best way to store lots of information (read only) for an iPhone/iPad app? [Can you also point me to a solid tutorial on how to store it? Many thanks in advance from a puzzled developer.]

[I don't need to load all the strings into my application at any one given time, only around 50 per each round of the game].

A: 

You should use an sqlite database. Here is one of many tutorials:

http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

vakio
+2  A: 

You have a few options off the top of my head: You can use a database or you can create an archive. Personally, I would use the archive approach, but a database in sqlite or CoreData will work just as well (and may even be faster).

To create an archive, your classes need to subscribe to the NSCoding protocol, implementing the two methods - (id) initWithCoder:(NSKeyedUnarchiver*)aDecoder and - (void) encodeWithCoder:(NSKeyedArchiver*)aCoder. These are used by calling [aCoder encodeObject: myString forKey: @"theKeyIWantToUse"]; and [self setMyString: [aDecoder decodeObjectForKey: @"theKeyIWantToUse"]];

Reading and writing data from an archive is very easy and relatively fast thanks to Apple's polish on the coding system.

Again, alternatively, you can build a CoreData backend that will manage object storage and retrieval in a database. This abstracts where data is stored and how it is accessed, which is very useful. Hope that helps!

Grimless
Yes it does.Thank you!
Salvi