I have the following code for saving a value and an string. I want to use If statement to check my value.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"Baseball bat" forKey:@"Weaponsname"];
NSInteger Attack1 = [defaults integerForKey:@"Attack"];
NSString *Weapon = [defaults stringForKey:@"Weaponsname"];
if([Weapon isEqual: @"Baseball bat"]){
[defaults setInteger:(Attack1+50) forKey:@"Attack"];
NSLog(@"Baseball bat");
}
[defaults synchronize];
So if i have the Baseball bat, the Attack should increase by 50. But it doesn't. What wrong with the code? Thanks