Skip to content

Instantly share code, notes, and snippets.

@pratikshabhisikar
Created August 12, 2011 10:37
Show Gist options
  • Save pratikshabhisikar/1141833 to your computer and use it in GitHub Desktop.
Save pratikshabhisikar/1141833 to your computer and use it in GitHub Desktop.
Saving username and password in userdefaults
#define USERNAME_KEY @"username"
#define PASSWORD_KEY @"password"
-(void) saveUser:(NSString *) username andPassword:(NSString *) password {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// Save the username.
[userDefaults setObject:username forKey:USERNAME_KEY];
[userDefaults synchronize];
// Save the password.
[userDefaults setObject:password forKey:PASSWORD_KEY];
[userDefaults synchronize];
}
-(void) someFunction {
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:USERNAME_KEY];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment