开发者

Best Ways to Store iPad/iPhone Application Data

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 goin开发者_如何学运维g 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? ]

[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].


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜