2

I am new to iOS programming - I have written an iOS app for a company that uses the app for their workers to log in when they go to work, and to log out when they leave. (They often work on remote places).

All I need now is a way to store two simple strings. 1. String is the user name 2. String is a salted md5 password

Then the user doesn't need to write all the credentials every time he wants to login and out.

What is the simples? SQLite, CoreData, Plst?

Thanks!

hogni89
  • 1,920
  • 6
  • 22
  • 39

1 Answers1

6

See my answer here:

I'd avoid using a plist. The easiest way to save simple data in an application, by far, is NSUserDefaults.

Check out this tutorial for a simple guide on how to use NSUserDefaults. Always be sure to synchronize NSUserDefaults when you're done writing to them.

Example:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// Storing an NSString:
NSString *user = @"MyUsername";
[prefs setObject:user forKey:@"username"];
[prefs synchronize];

Later:

// Retrieving an NSString:
NSString *savedUserName = [prefs stringForKey:@"username"];
Community
  • 1
  • 1
mopsled
  • 8,445
  • 1
  • 38
  • 40
  • Nice! I didn't know it was THIS easy! I have actually set up an SQLite, but it's extreme overkill for a username and a password - But now I know how to use SQLite AND NSUserDefaults :) BTW, how much data can you store in NSUserDefaults? – hogni89 Aug 17 '11 at 21:36
  • http://stackoverflow.com/questions/7510123/is-there-any-limit-in-storing-values-in-nsuserdefaults – Max Aug 07 '13 at 21:53