Possible Duplicate:
Comparing Strings in Cocoa
Why is this code not recognising the NSString as being equal?
I have a value set to @"YES" in the NSUserDefaults. When I run this method...
- (void) checkForHint {
NSLog(@"call:checkForHint");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"valueForKeyInDefaults:%@",[defaults valueForKey:@"giveHint"]);
if ([defaults valueForKey:@"giveHint"] == @"YES") {
NSLog(@"need to give hint");
// replace a letter at random
int i=0;
bool found = NO;
while (!found && i<NUM_CHARACTERS_IN_LEVEL_STRING) {
NSLog(@"searching at index %i",i);
if ([buttons objectAtIndex:i] && 32==[[levelSavedSolutionArray objectAtIndex:i] intValue]) {
found = YES;
}
i++;
}
i--;
// We need to select all the buttons at this unsolved space
[self buttonClicked:[buttons objectAtIndex:i]];
// update the entries in all selected buttons
[self keyAct:[[levelStringArray objectAtIndex:i] intValue]];
}
}
the output to the console is:
2012-03-28 23:11:41.799 (APPID) call:checkForHint
2012-03-28 23:11:41.800 (APPID) valueForKeyInDefaults:YES
I dont understand why this if statement isnt returning true.. Anyone who could help that would be greatly appreciated. I have a feeling its because the two strings are different instances that happen to have the same values but I dont know how to fix this.