I am having a problem in my sprite kit app where my NSUserDefaults
variable is not working. In createSceneContents
(which I know is being called)
if (![defaults objectForKey:@"obj"]) {
difficultyLabel.text = @"Difficulty: Easy";
[defaults setObject:@"Easy" forKey:@"obj"];
} else {
difficultyLabel.text = [NSString stringWithFormat:@"Difficulty: %@", [defaults objectForKey:@"diff"]];
}
and then when you click on the SKLabelNode
to change the difficulty and this code is being called
if ([label.text isEqualToString:@"Difficulty: Easy"]) {
label.text = @"Difficulty: Hard";
[defaults setObject:@"Hard" forKey:@"obj"];
NSLog(@"%@",[defaults objectForKey:@"obj"]);
} else {
label.text = @"Difficulty: Easy";
[defaults setObject:@"Easy" forKey:@"obj"];
NSLog(@"%@",[defaults objectForKey:@"obj"]);
but when I stop the program and run it again, it always just says Difficulty: Easy. Any suggestions?