Skip to content

Instantly share code, notes, and snippets.

@swarut
Created October 31, 2012 16:59
Show Gist options
  • Save swarut/3988292 to your computer and use it in GitHub Desktop.
Save swarut/3988292 to your computer and use it in GitHub Desktop.
Objective-C : Using UserPreference #objective-c #userpreference
userPreference = [NSUserDefaults standardUserDefaults];
// Check for a value of a specific key
if([userPreference objectForKey:@"login_info"]){
NSString *userInfo = [userPreference objectForKey:@"login_info"];
NSArray *tokens = [userInfo componentsSeparatedByString:@"/"];
[self.telephoneTextField setText:[tokens objectAtIndex:0]];
[self.passwordTextField setText:[tokens objectAtIndex:1]];
[self login:self];
}
// save login so that the user doesn't have to input login info again
if([userPreference objectForKey:@"login_info"] == nil){
NSString *user_info = [NSString stringWithFormat:@"%@/%@", telephoneTextField.text, passwordTextField.text];
[userPreference setValue:user_info forKey:@"login_info"];
[userPreference synchronize];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment