wallou
wallou

Reputation: 579

NSUserDefaults - reload needed?

I use NSUserDefaults to store some stuff.

It works fine but only after i restart the app.

I use: [prefs synchronize]; I thought it would immediately save the data but instead preferences stay null.

If you have any idea or already deal with it let me know. Thanks for any help.

Wallou

Upvotes: 2

Views: 1665

Answers (1)

wallou
wallou

Reputation: 579

I finally managed to solve my issue. I was doing the same thing at two different places (old code forgotten somewhere). For information here is my code:

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
// saving an NSString
[prefs setObject:identField.text forKey:@"mail"];
[prefs setObject:pwdField.text forKey:@"password"]; 
mail=[prefs objectForKey:@"mail"];
pwd=[prefs objectForKey:@"password"];

//This is to synch prefs
[prefs synchronize];
NSLog(@"pwd: %@, username:%@", mail, pwd);

Upvotes: 2

Related Questions