iPhone preferences (NSUserDefaults) not working, keys always return nil -


I have made some preferences in my settings. The bundle that looks fine in the settings app. Although my settings always come back to zero when I read them back. I know that I must first set the default value at startup but after that and also going to the settings menu (whatever the default value should be set) - when I have read them back, I always get zero.

Even when I set the default and read it immediately, I get zero!

  NSUserDefaults * defaults = [NSUserDefaults StandardUserDefaults]; NSDictionary * App Defaults = [Object with NSDictionary: @ "Yes" for: @ "Displays Times"]; [Default register defaults: app defaults]; [Synchronize default]; Bool test = [Error boolForKey: @ "displaySunTimes"]; NSLog (@ "value% @", exam);  

Here's the start of my root. Plist

  & lt; Dict & gt; & Lt; Key & gt; StringsTable & lt; / Key & gt; & Lt; String & gt; Root & lt; / String & gt; & Lt; Key & gt; PreferenceSpecifiers & lt; / Key & gt; & Lt; Array & gt; & Lt; Dict & gt; & Lt; Key & gt; & Lt; / Key & gt; & Lt; String & gt; PSGroupSpecifier & lt; / String & gt; & Lt; Key & gt; Title & lt; / Key & gt; & Lt; String & gt; Show sunrise / sunset for your location. & Lt; / String & gt; & Lt; / Dict & gt; & Lt; Dict & gt; & Lt; Key & gt; & Lt; / Key & gt; & Lt; String & gt; PSToggleSwitchSpecifier & lt; / String & gt; & Lt; Key & gt; Title & lt; / Key & gt; & Lt; String & gt; Sunrise / Sunset & lt; / String & gt; & Lt; Key & gt; Key & lt; / Key & gt; & Lt; String & gt; DisplaySunTimes & lt; / String & gt; & Lt; Key & gt; DefaultValue & lt; / Key & gt; & Lt; True /> & Lt; Key & gt; TrueValue & lt; / Key & gt; & Lt; String & gt; Yes & lt; / String & gt; & Lt; Key & gt; FalseValue & lt; / Key & gt; & Lt; String & gt; No & lt; / String & gt; & Lt; / Dict & gt;  

Use this if you want to store a BOOL:

  [[NSUserDefaults Standard User Defaults] Setbool: Yes for Y: @ "Displays Times"];  

To recover it by default:

  [[NSUserDefaults standard user default] boolForKey: @ "displaySunTimes"];   

Edit :
NSLog (@ "value% @", test); Change NSLog from (@ "value% i", test); (The BOOL is not the object).
> Additionally, use BOOL instead of bool


Comments