Mujib Saiyyed
Mujib Saiyyed

Reputation: 158

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?

Upvotes: 5

Views: 2148

Answers (5)

user2435304
user2435304

Reputation:

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 .

Upvotes: 0

Leo
Leo

Reputation: 24714

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).

Upvotes: 18

Avijit Nagare
Avijit Nagare

Reputation: 8802

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

Upvotes: 1

Sajad Garshasbi
Sajad Garshasbi

Reputation: 508

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.

Upvotes: 1

Laky
Laky

Reputation: 632

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 :)

Upvotes: 1

Related Questions