How to save a BOOL in iOS app

风流意气都作罢 提交于 2019-12-25 04:19:47

问题


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?


回答1:


You should add the following code

[[NSUserDefaults standardUserDefaults] synchronize];



回答2:


[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"kLogIn"];
[[NSUserDefaults standardUserDefaults] synchronize];



回答3:


[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"testingBool"];
BOOL test = [[NSUserDefaults standardUserDefaults] boolForKey:@"testingBool"];


来源:https://stackoverflow.com/questions/29926820/how-to-save-a-bool-in-ios-app

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