Is it okay to use NSUserDefaults instead of Database?
Asked Answered
S

5

5

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?

Slovenia answered 7/8, 2015 at 5:7 Comment(2)
https://mcmap.net/q/373811/-nsuserdefaults-vs-sqlite3Buffo
I think it isn't. NSUserDefaults just useful for setting, configuration with simple data. In case you want to work with more data, I think you should use CoreData or SQLite.Saturable
L
18

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).
Lam answered 7/8, 2015 at 5:31 Comment(1)
Thanks Leo, That explanation was more than i was expecting. :)Slovenia
D
1

NSUserDefaults is typically used for storing small pieces of data such as application settings, preferences, and individual values such as 'email', 'remember me' options and etc.

So based on the amount of data that you planing to store in the app, if the items fall under the above mentioned category it's totally fine to use NSUserDefaults. But when it comes to string substantial amount of data like collection of item, check-list, contacts, etc it's better to look at other approaches of saving them in a database.

For starters you can look at these Github libraries to help you out if you want to use the database approach. FMDB, OLCOrm

Hope this answer your question :)

Dux answered 7/8, 2015 at 5:19 Comment(0)
D
1

if your data is not heavy and you will not need to get query from this NSUserDefaults can help you, but the better solution for saving data except using database is file.

Dawna answered 7/8, 2015 at 5:21 Comment(0)
C
1

If you have small number of array then you can user NSUserDefaults. Otherwise Property list you can use. check this link.hope this will help.

Updating and saving data in plist

Club answered 7/8, 2015 at 5:23 Comment(0)
K
0

If you want to use operations of a database like adding, deleting or updating data later on then its recommended to use database libraries like CoreData Or Sqlite Otherwise if your data is not that big and it is mostly static then it is totally fine to use NSUserDefaults .

Kamilahkamillah answered 7/8, 2015 at 5:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.