Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

objective-c

if(lyricsId == areleased.trackId)

{
  ----------;
  ----------;
}

when i am working with above code it does not entered into that loop So, I used the below code,then it entered into the loop and i got out put.

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

}

Is there any difference between == and isEqualToString.

like image 578
Madan Mohan Avatar asked Apr 07 '10 12:04

Madan Mohan


2 Answers

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

like image 120
Marcelo Cantos Avatar answered Nov 17 '22 19:11

Marcelo Cantos


== will compare pointers(addresses) equality, while isEqualToString:will compare if one string is equal to another.

like image 5
mxg Avatar answered Nov 17 '22 17:11

mxg