Comparing a nil NSString with another valued NSString returns NSOrderedSame
18:56 28 Mar 2011

I'm testing a string with an other, and I notice that if the first string is nil, the return value equals NSOrderedSame (valued to 0).

if([oneString compare:otherString] == NSOrderedSame) returns YES if oneString is nil.

So I should test if(oneString != nil && [oneString compare:otherString] == NSOrderedSame)

I guess I should also test otherString in the condition, and make a special case if I want that [nil compare:nil] returns NSOrderedSame.

Is there a more convenient way to compare string without having to do such tests and to really test if both strings are the same ?

objective-c iphone compare nsstring equality