0

I created a bundle setting for my app with these options:

and now I have this class called LHTabBarController.m

and I am trying to get the value of Update Lot like so:

Item 1 (Toggle Switch - Update Lot) - Type - Toggle Switch, Title - Update Lot, Identifier - update_lot, Value for ON - YES, Value for OFF - NO, Default Value - YES

BOOL updateLot = [[NSUserDefaults standardUserDefaults] valueForKey:@"update_lot"];

but no matter what it returns as NO when the default is YES....what am I doing wrong here?

In the bundle settings, the setting is on as expected, but I can't seem to get that value. I hope I don't have to do this in AppDelegate because I need to use this value in my class.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Magna Boss
  • 289
  • 5
  • 11
  • 1
    Don't use `valueForKey:` with `NSUserDefaults`. And besides, you can't assign the result of `valueForKey:` to a `BOOL` variable. Don't ignore compiler warnings. – rmaddy Sep 25 '15 at 20:51
  • And keep in mind that the default values set in a Settings bundle will not appear in returned values from `NSUserDefaults`. – rmaddy Sep 25 '15 at 20:53

1 Answers1

1

Try using boolForKey instead:

BOOL updateLot = [[NSUserDefaults standardUserDefaults] boolForKey:@"update_lot"];

Foundation Framework Reference > NSUserDefaults Class Reference

l'L'l
  • 44,951
  • 10
  • 95
  • 146