Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NSUserDefaults to store many values will cause problems?

I have created an application which will login using username, password and allows the user to download the files from serve. In my application I have to persist few datas once the user have login in the application.

Persisting data like Username, Password, user downloaded list , subscribed plans,etc. The data can be persisted in application either by NSUserDefaults,Plist , etc. But I feel easy to store and retrieve the values using NSUserDefaults. As I need to use the values in many view controllers, I prefer NSUserDefaults.

Is this the best practice ? Using too much NSUserDefaults will result in a trap ? Tell me is there other way to persist the data and retrieve it easily in cocoa-touch ?

like image 400
Cyril Avatar asked Jun 22 '26 22:06

Cyril


2 Answers

You can use NSUserDefaults for storing user data.

But for highly sensitive data like Username and Password I prefer keychain to store them.

Please check these links for Keychain saving:

  1. Simple iphone keychain access
  2. saving email password to keychain in ios
  3. howto use keychain in iphone sdk
like image 175
Midhun MP Avatar answered Jun 24 '26 13:06

Midhun MP


In my opinion , if you want to store little data , such as username , password or some BOOLs , you can use NSUserDefaults .

As the NSUserDefaults is a common plist , if you want to store some your data such as your download links , it is better to use your custom plist .

If you want to store some big data such as UIImage , you can use NSCache , but it may evict data.

If you want to store a lot of data , it better to use database.

like image 26
Guo Luchuan Avatar answered Jun 24 '26 13:06

Guo Luchuan