storing data locally on the iphone storing data locally on the iphone database database

storing data locally on the iphone


For simple data you should use NSUserDefaults. CoreData is very cool but mainly to store DB structures, and introduces complexity (but i love it:)). If you just need to store String, Array and so on (basically prefs), you can go with NSUserDefaults:

For example:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];  //load NSUserDefaultsNSArray *fakeFavs = [[ NSArray alloc] initWithObjects:@"2",@"4", @"100", nil];  //declare array to be stored in NSUserDefaults[prefs setObject:fakeFavs forKey:@"favourites"];  //set the prev Array for key value "favourites"


You have basically two options to store data:

  1. CoreData (if you are planning to use newer versions of iOS)
  2. SQLite (supports any version of the SDK)

CoreData uses SQLite, its API is a little bit easier to use (you don't need to know SQL or write a lot of functions to read and write your data).

SQLite API is still a great choice, since it uses the C API for SQLite, which is very well documented and straightforward to use. It has the benefit that you can target older iOS platforms with this.

With both options, data will be stored client side, and will be backed every time user syncs his/her phone with iTunes.


if you just storing a few values and don't need any search logic, you could take a look into NSUserDefaults

[NSUserDefaults standardUserDefaults] 

its just an dictionary where you can store arrays, strings, int, objects and access by a NSString key

internally it's a just plist, so you can open it with xcode to quicky see the current state