NSUserDefaults. setValue works, Not setBool

前端 未结 4 1732
春和景丽
春和景丽 2021-01-18 02:16

I trying to store some settings in NSUserDefaults, but It seems that the app won\'t store the setBool values.

This works:

[[NSUserDefaults standardUs

4条回答
  •  感动是毒
    2021-01-18 02:45

    How can you be sure its not working? I tried your code and it works for me. Are you sure you are reading the Boolean in the correct way AFTER you write it?

    This code SHOULD work:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:NO forKey:@"test"];
    
    [defaults synchronize];
    
    BOOL myBool = [defaults boolForKey:@"test"];
    

提交回复
热议问题