If “a == b” is false when comparing two NSString objects

You’re assuming that the C == operator does string equality. It doesn’t. It does pointer equality (when called on pointers). If you want to do a real string equality test you need to use the -isEqual: method (or the specialization -isEqualToString: when you know both objects are strings):

if ([mySecondString isEqualToString:myString]) {
    i = 9;
}

Leave a Comment