I am writing an iPhone application, and need to save the state of my application (5K or so).
My main worry is data persisting across upgrades. Some of the applications I use clearly got this wrong, and I would prefer not to!
I am writing an iPhone application, and need to save the state of my application (5K or so).
My main worry is data persisting across upgrades. Some of the applications I use clearly got this wrong, and I would prefer not to!
The most common way to save state (data, application information etc) is to use Sqlite3. I'm not sure how an update would wipe it, but it's possible that the update process could overwrite the datafile.
The other option would be to use UserPrefs (NSUserDefaults). Again, I'm not sure the max size for that, or even if it would be suitable for the data you need to persist.
I use sqlite to store all application data, and preferences. To make sure that updates do not wipe the data, make sure the sqlite file is stored in the Documents directory of the application, which is not overwritten by upgrades. Some of the example code ("SQLite Books" I think) Apple provides has code to handle this.
To save state, NSUserDefaults is the way to go. I believe most, if not all, instances of application data being deleted after an upgrade are due to issues on the AppStore. They may be related to data-format changes, but if you use just NSUserDefaults and standard plist-storable objects (NSString, NSDictionary, NSNumber, NSArray, NSNumber, and primitives), you should be safe.
It really depends on what you're doing and your needs.
If it's a small amount of data NSUserDefaults is a great way to go. You can also save a dictionary or an array to your apps Documents folder, then load that file back in on launch.
SQLite is nice, but unless you've got a lot of data that you'll be querying, it's a little over the top for just saving state.
for small amounts of data NSUserDefaults is a perfect solution, if you need ad hoc querying of data sqlite is the way to go. Those two solutions are perfect for storing data on the device, if you need more flexibility and capability you could consider remote data i.e web services and a server database.