Can NSUserDefaults be used instead of a database?

I am new to iOS, so please spare me if I am asking something that everyone knows or something is wrong.

I need to store some arrays and references in my application. So instead of a database, I used NSUserDefaults

. I know what NSUserDefaults

contains the values ​​until we uninstall the app or clear the app data. So I just need to know what can be used NSUserDefaults

instead of using a database?

+3


source to share


5 answers


When I store data:



  • User preference data: settings, accounts ... - NSUserDefaults
  • Security data: passwords - KeyChain
  • Small amount of data that does not require a complex query - Plist, Archiver
  • Large amount of data requiring a structured query - Coredata / SQLite (FMDB) .
+10


source


NSUserDefaults

It is usually used to store small pieces of data such as application settings, preferences, and individual values ​​such as email, remember me, etc. options.

So, based on the amount of data you plan to store in your application, if items fall into the above category, NSUserDefaults can be used. But when it comes to entering a significant amount of data such as item collection, checklist, contacts, etc., it is better to look at other ways to save it to the database.



To get started, you can take a look at these Github libraries to help you if you want to take a database approach. FMDB , OLCOrm

Hope the answer to your question :)

+1


source


if your data is not heavy and you will not need to receive a request from this NSUserDefaults it might help you, but the best solution to save data other than using a database is a.

+1


source


If you have a small number of arrays, you can use NSUserDefaults. Otherwise, you can use a property list. check this link. Hope this helps.

Updating and saving data in plist

+1


source


If you want to use type database operations adding, deleting or updating

later then it is recommended to use database libraries such as CoreData Or Sqlite

Otherwise, if your data is not that big and it is mostly static, then it is quite ok to use NSUserDefaults

.

0


source







All Articles