What is the difference between isEqualToString and == operator in Objective-C?

if(lyricsId == areleased.trackId) { ----------; ----------; } 

when I work with the above code, it is not introduced into this loop. So, I used the code below, then it went into the loop, and I got out of it.

 if([lyricsId isEqualToString:areleased.trackId]) { ----------; ----------; } 

Is there a difference between == and isEqualToString.

+7
objective-c
source share
2 answers

lyricsId and arelease.trackId are (I suppose) of type NSString* . == simply compares pointers, which will usually differ, even if their contents are the same. The isEqualToString method compares their contents.

+11
source share

== will compare the equality of pointers (addresses), and isEqualToString: will compare if one row is equal to another.

+5
source share

All Articles