-1

I'm trying to set userDefaults, but it isn't working. Have anyone else experience this problem? Tried both on simulator and device. Xcode 6.3.1 and iOS 8.3

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:YES forKey:@"active"];
BOOL active = [defaults boolForKey:@"active"]; // RETURN NO
Alex Andrews
  • 1,498
  • 2
  • 19
  • 33
BlackMouse
  • 4,442
  • 6
  • 38
  • 65

1 Answers1

3

chek this code: you missing synchronize nsuserdefault.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:YES forKey:@"active"];
[defaults synchronize];
BOOL active = [defaults boolForKey:@"active"]; 
Chandan kumar
  • 1,074
  • 12
  • 31