Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it okay to use NSUserDefaults instead of Database?

I am new to iOS, so please spare me if i am asking something thats known to everyone or something wrong.

I need to save some Arrays and links in my app. So i used NSUserDefaults instead of Database. I know that NSUserDefaults holds the values until we uninstall the app or somehow clear the app data. So I just need to know, Is is ok to use NSUserDefaults instead of using database?

like image 801
Mujib Saiyyed Avatar asked Aug 07 '15 05:08

Mujib Saiyyed


People also ask

Is NSUserDefaults thread safe?

Thread SafetyThe UserDefaults class is thread-safe.

Should I use UserDefaults?

When to Use User Defaults? The defaults system is ideal for storing small chunks of data, such as settings or the user's preferences. The user's defaults database is stored on disk as a property list or plist. A property list or plist is an XML file.

What is NSUserDefaults?

A property list, or NSUserDefaults can store any type of object that can be converted to an NSData object. It would require any custom class to implement that capability, but if it does, that can be stored as an NSData. These are the only types that can be stored directly.

Is NSUserDefaults encrypted?

NSUserDefaults are stored in plist in binary format, with no encryption, and is stored in your app's directory.


1 Answers

When I store data:

  1. User preference data: Settings,Accounts... - NSUserDefaults
  2. Security data:passwords - KeyChain
  3. Small amount of data that do not need complex query - Plist,Archiver
  4. Big amount of data which need Structured Query - Coredata/SQLite(FMDB).
like image 155
Leo Avatar answered Oct 17 '22 02:10

Leo