What are the limitations of NSUserDefaults?

Sqlite3 is more useful for keeping large database and to access to the database elements. You can sort the items of Sqlite3 database, you can search very fast for item in Sqlite3 dtabase. Sqlite3 database has many privileges that NSUserDefaults didn’t have !


NSUserDefaults vs Sqlite3

NSUserDefaults is for user preferences, usually basic objects like NSString or NSNumber. Sqlite, serializing a collection of objects in a property list, or Core Data are all valid options for storing user data such as model objects you created.

You’re not going to see a speed difference, but it’s still best to pick the correct mechanism for what you’re doing. If it’s just preferences then use NSUserDefaults, otherwise I would serialize your objects to a plist. If you’re new to Cocoa I would avoid Core Data and even Sqlite at first, to give yourself a chance to learn the basics first.


NSUserDefaults or Sqlite

When you want to store large amount of data with some relationship, go for Sqlite if you want to store less value go for NSUserDefaults. Sqlite occupies some memory so use it only you really need to save complex datas.


Using NSUserDefaults to save a lot of game data

Usually NSUserDefaults is used to save game settings. To save game data, it’s usually better to use either SQLite or you could create a NSDictionary of objects and save to disk, here couple of post that may help:

  1. http://www.cocos2d-iphone.org/forum/topic/9308
  2. http://www.cocos2d-iphone.org/forum/topic/9210

Leave a Comment