6

In Java you can write an if statement like this:

if(object1.equals(object2)){ // Do something.... }

How can I code the same logic in Objective-C? I basically want to compare 2 of any one type of objects, such as 'Text Fields', 'Text Views', etc.

Thank you.

Shakeel

user339076
  • 431
  • 2
  • 5
  • 4
  • This is a duplicate of this question: http://stackoverflow.com/questions/1319247/how-to-compare-if-two-objects-are-really-the-same-object – Brad Larson May 12 '10 at 12:57

1 Answers1

30

It's pretty similar!

if ([object1 isEqual:object2])

see the NSObject protocol documentation.

Pang
  • 9,564
  • 146
  • 81
  • 122
deanWombourne
  • 38,189
  • 13
  • 98
  • 110
  • 2
    Because it's a protocol; there isn't an implementation for it to describe! You need to look at what an implementation of that protocol does - http://stackoverflow.com/questions/1241575/what-is-the-nsobject-isequal-and-hash-default-function – deanWombourne May 14 '13 at 13:26