NSUserDefaults not working right

后端 未结 3 582
耶瑟儿~
耶瑟儿~ 2020-12-21 01:38

Having some trouble with NSUserDefaults here.

Here\'s how I\'m creating it:

NSString *theCity = @\"Test City\";
[[NSUserDefaults standar         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-21 02:04

    I ran into a similar problem myself recently. Here's what fixed it for me.

    From the iOS Application Programming Guide:

    It is recommended that you register any default preference values programmatically at launch time in addition to including them in your settings bundle property lists. For newly installed applications, default preference values from the application’s settings bundle are not set until the Settings application runs. This means that if the user runs your application before running Settings, the default values specified in your settings bundle will not be available. Setting such values programmatically at launch time ensures that your application always has appropriate values. To register default values programmatically, use the registerDefaults: method of the NSUserDefaults class.

提交回复
热议问题