Why can't I save changes to application settings with NSUserDefaults?
Posted
by Brennan
on Stack Overflow
See other posts from Stack Overflow
or by Brennan
Published on 2010-03-19T14:38:18Z
Indexed on
2010/03/19
14:41 UTC
Read the original article
Hit count: 275
I am using the following code to save values from a settings view that takes values from a UITextField and stores them with NSUserDefaults. The code below even calls synchronize yet it is not saving the changes. What am I doing wrong here?
- (IBAction)save {
NSLog(@"save");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (self.usernameTextField.text != nil) {
NSLog(@"username: %@", self.usernameTextField.text);
[defaults setObject:kTwitterUsernameKey forKey:self.usernameTextField.text];
}
if (self.passwordTextField.text != nil) {
NSLog(@"password: %@", self.passwordTextField.text);
[defaults setObject:kTwitterPasswordKey forKey:self.passwordTextField.text];
}
[defaults synchronize];
[self dismissModalViewControllerAnimated:TRUE];
}
© Stack Overflow or respective owner