我试图像这样使用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;

10-08 05:32