NSUserDefaults default value returning (null)?

好久不见. 提交于 2019-12-24 12:53:00

问题


This is probably something really simple that I am missing, why when using the code below to access settings does the default value return as (null)

- (void)updateUIForDistanceUnits {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *test = [userDefaults stringForKey:@"IDDistance"];
    NSLog(@"DISTANCE: %@", test);
}

Root.plist


回答1:


The default value in Root.plist is just what the UI shows if there's no value set, and you have to do the same in your code or set up [NSUserDefaults -registerDefaults] correctly in your application.

You should find that once you set the value in Settings.app NSUserDefaults will return the correct value.



来源:https://stackoverflow.com/questions/10706685/nsuserdefaults-default-value-returning-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!