How to save a BOOL in iOS app

2019-08-21 17:03发布

I used the following code to save a BOOL but it's not working.

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"save"];
StrongMAN = [[NSUserDefaults standardUserDefaults] boolForKey:@"save"];

Are there other ways to save a BOOL?

3条回答
叼着烟拽天下
2楼-- · 2019-08-21 17:51

You should add the following code

[[NSUserDefaults standardUserDefaults] synchronize];
查看更多
Fickle 薄情
3楼-- · 2019-08-21 17:53
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"testingBool"];
BOOL test = [[NSUserDefaults standardUserDefaults] boolForKey:@"testingBool"];
查看更多
地球回转人心会变
4楼-- · 2019-08-21 18:05
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"kLogIn"];
[[NSUserDefaults standardUserDefaults] synchronize];
查看更多
登录 后发表回答