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];
}