问题
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