Is there a difference between NSString compare: and isEqual(ToString): ?

Posted by frenetisch applaudierend on Stack Overflow See other posts from Stack Overflow or by frenetisch applaudierend
Published on 2010-05-20T20:09:11Z Indexed on 2010/05/20 20:10 UTC
Read the original article Hit count: 208

Filed under:
|

Occasionally I find code which tests if two NSStrings are the same like this:

if ([str1 compare:str2] == NSOrderedSame) {
    // Do something
}

Now, I believe this is less readable than using isEqualToString: and it also has some nasty side effects, like if str1 == nil the if(..) evaluates to true, or when str2 == nil havoc might break upon us according to the Apple docs.

But before I crusade against those statements in my companys code, I wanted to make sure I didn't miss some important point.

So my question basically boils down to: Is there any difference between a compare: to NSOrderedSame and isEqual:?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nsstring