This is due to what testStringmay equal nil. Sending a message in nilreturns nil. NSOrderedSameequal 0and 0equal nil.
NSLog(@"nil == NSOrderedSame = %d", (nil == NSOrderedSame));
NSLog(@"[nil compare:@\"arf\"] == nil = %d", ([nil compare:@"arf"] == 0));
To avoid this, make sure that before comparing the object is not nil, for example:
if (testString != nil && [testString compare:@"testString"] == NSSOrderedSame) ...
NB: I added this question so as not to repeat this error again.
source
share