user339076
user339076

Reputation: 431

How to compare 2 objects for equality in Objective-C

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

Upvotes: 6

Views: 14996

Answers (1)

deanWombourne
deanWombourne

Reputation: 38485

It's pretty similar!

if ([object1 isEqual:object2])

see the NSObject protocol documentation.

Upvotes: 30

Related Questions