PDA

View Full Version : comparing two objects




sujithkrishnan
Jan 7, 2009, 06:16 AM
Hi all,
i want to know how to compare the content of two objects.isEqualTo compares the reference.I tryed using isEqualTo,even though the values of properties are same it is returning no.



CommanderData
Jan 7, 2009, 07:04 AM
Hi all,
i want to know how to compare the content of two objects.isEqualTo compares the reference.I tryed using isEqualTo,even though the values of properties are same it is returning no.

What do the objects contain? Can you be more specific? NSStrings? Custom Classes?

SqueegyX
Jan 7, 2009, 11:06 AM
If its your own class, implement your own isEqual: method. Test if its the same class, then compare its values.

By befault, 2 NSSobjects are only the same if they are the same objects. Meaning if you instantiate 2 object with the same values, they will be be "Equal". Classes like NSString override the isEqual: method in order change what is considered "Equal".

sujithkrishnan
Jan 8, 2009, 12:23 AM
Thanks.Ya it's my own class,two objects which i am comparing are of same type and thay have the same contents also,but the refrences are diffrent.So in this scenario do i still need to implement my own isEqual method?

dejo
Jan 8, 2009, 10:41 AM
So in this scenario do i still need to implement my own isEqual method?
Yup, you do.