我试图像这样使用NSInteger
增加NSUserDefaults
:
NSInteger attempts = [[NSUserDefaults standardUserDefaults]integerForKey:@"tries"];
NSInteger newA = attempts++;
[[NSUserDefaults standardUserDefaults]setInteger:newA forKey:@"tries"];
[[NSUserDefaults standardUserDefaults]synchronize];
NSLog(@"Tries: %d",[[NSUserDefaults standardUserDefaults]integerForKey:@"tries"]);
但这是我的
NSLogs
:Tries: 0
Tries: 0
Tries: 0
最佳答案
这是你的问题
NSInteger newA = attempts++;
将其设置为newA后,您将增加尝试次数,请尝试以下方法:
NSInteger newA = ++attempts;