开发者

Where do I put registerDefaults?

开发者 https://www.devze.com 2023-03-31 07:31 出处:网络
I want to l开发者_Python百科oad and save settings. I don\'t know where I put registerDefaults. I put it in loadSetting. I think I did wrong. Do I have to put it at the end of application didFinishLau

I want to l开发者_Python百科oad and save settings. I don't know where I put registerDefaults. I put it in loadSetting. I think I did wrong. Do I have to put it at the end of application didFinishLaunch?

  - (void)loadSettings {    
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

        NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], @"key1",
                         [NSNumber numberWithBool:NO], @"key2",
                         nil];
        [defaults registerDefaults:dictionary];

        key1Value = [defaults boolForKey:@"key1"];
        key2Value = [defaults boolForKey:@"key2"];
    }

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  NSDictionary *)launchOptions  {    
        [self loadSettings];

    }


It looks ok to me. I think as long as you call it before any views are loaded, you should be fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号