comparing two objects

Discussion in 'iPhone/iPad Programming' started by sujithkrishnan, Jan 7, 2009.

  1. macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #1
    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.
     
  2. macrumors regular

    Joined:
    Dec 1, 2007
    #2
    What do the objects contain? Can you be more specific? NSStrings? Custom Classes?
     
  3. macrumors regular

    Joined:
    Mar 24, 2008
    #3
    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".
     
  4. thread starter macrumors 6502

    Joined:
    May 9, 2008
    Location:
    Bangalore
    #4
    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?
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Yup, you do.
     

Share This Page