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/
精彩评论