开发者

Best way to save data in iPod Touch/iPhone Objective-C

开发者 https://www.devze.com 2022-12-22 19:56 出处:网络
I am writing a very simple application, for the iPhone. Unfortunately I am really a newbie. What I am trying to do is to save data at the end of a user experience. This data is really simple, only str

I am writing a very simple application, for the iPhone. Unfortunately I am really a newbie. What I am trying to do is to save data at the end of a user experience. This data is really simple, only string or int, or some array.

Later I want to be able to retrieve that data, therefore I also need an event ID (I suppose).

Could you please point out the best way, API or technology to achieve that, XML, plain开发者_StackOverflow中文版 text, serialization... ?


Use NSUserDefaults. Straight forward and easy to use. This will handle all File I/O for you, and takes only a couple lines of code.


NSUserDefaults is a good choice for small amounts of data.

If you need to manage something larger than a kilobyte or so, you might consider using the initWithContentsOfFile: methods of NSArray or NSDictionary to read in a .plist file. To write the file, use the writeToFile:atomically: methods. This file needs to go in your app's documents directory.


Me and my team created a simple class for this purpose which as Mark pointed out makes use of NSUserDefaults. Hopefully this helps you out...

http://getsetgames.com/2009/10/07/saving-and-loading-user-data-and-preferences/

0

精彩评论

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