iPhone and NSUserDefaults

后端 未结 2 948
一生所求
一生所求 2021-01-07 05:25

In my viewWillLoad: method I\'m currently doing something along these lines:

- (void)viewWillAppear:(BOOL)animated {
   NSUserDefaults *defaults = [         


        
相关标签:
2条回答
  • 2021-01-07 05:51

    You should provide defaults in your code using -registerDefaults:. This is typically done in an +initialize method for whatever class uses the settings. See Using NSUserDefaults.

    0 讨论(0)
  • 2021-01-07 05:57

    Using the initialize method works but I like this other answer on stackoverflow that has code to read the default values from the bundle and uses them to initialize the defaults. That way you don't have to hardcode the default settings in the code, they are in the plist where they belong.

    0 讨论(0)
提交回复
热议问题