The best approach to preserving the preferences of multiple users (NSUserDefaults, XML file or database)

I am creating one iOS application with the ability to manage users and log in.

I want to save user data settings for each user, but I'm not sure if this is the best way to save this setting for each user.

Should I save data in xml or NSUserDefaults file or even save it in my Parse Cloud database?

I just want to keep the list of user properties when loading the view, but I have to consider that my application should load the correct parameter for the current user.

For instance:

User: Peter trackingSwitchEnabled: YES

User: Molly trackingSwitchEnabled: NO

User: Paul trackingSwitchEnabled: YES

+4
source share
5 answers
  • Do not use the keychain if you do not store confidential information.
  • Do not use Core Data or XML (unless it's a plist) because it is a lot of work.
  • Do not use Parse unless you have a reason, because your user data will depend on how you pay for the account and users who can connect.
  • Use NSUserDefaults with key = user, value = JSON string. You can parse this to / from the object.
  • Use a complex key if you are too lazy, for example: key = "Mary | tracking", value = YES.

Bonus ASCII art!

NSUserDefaults plist Core Data SQList Full text search ✘ ✘ ✘ βœ” Complex search ✘ ✘ βœ” βœ” Binary data ✘ ✘ βœ” βœ” Allows complex data β˜… β˜…β˜… β˜…β˜…β˜…β˜… β˜…β˜…β˜…β˜… Performance β˜… β˜… β˜…β˜…β˜… β˜…β˜…β˜…β˜… Learning curve β˜… β˜…β˜… β˜…β˜…β˜… β˜…β˜…β˜…β˜… 
+10
source

If you want to use NSUserDefaults, you must use initWithSuiteName: to create another database.

[[NSUserDefaults alloc] initWithSuiteName: USER_IDENTIFY ]

+2
source

Here is a good settings guide for the app.

About settings and settings

In short, you should use NSUserDefaults.

0
source

Using NSUserDefault is not a good idea to save user login information. It is better to use Dynamic plist or xml. please read this for another better way.

0
source

To save user credentials, I would suggest using the KeychainItemWrapper class from apple:

You use it to save such values ​​(e.g. with email / password text fields)

  KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"myAppLogin" accessGroup:nil]; [keychainItem setObject:txtPassword.text forKey:(__bridge id)(kSecValueData)]; [keychainItem setObject:txtEmail.text forKey:(__bridge id)(kSecAttrAccount)]; } 

And then when you want to get the values ​​back from the keychain, you simply:

  KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"myAppLogin" accessGroup:nil]; NSMutableDictionary *myDictionary = [[NSMutableDictionary alloc]init]; [myDictionary setObject:[keychainItem objectForKey:(__bridge id)(kSecAttrAccount)] forKey:@"email"]; [myDictionary setObject:[keychainItem objectForKey:(__bridge id)(kSecValueData)] forKey:@"password"]; 

Also, be sure to download KeychainItemWrapper.h and .m from the developer.apple.com link I posted on top :)

So yes, basically explained what Steve said :)

0
source

All Articles