I am transcribing some C++ code into ObjC. The operator==() that I am looking at compares its private members one-by-one and returns true iff they are all true.
What is the equivalent implementation of operator==() in ObjC?
From browsing, I see in ObjC:
- -isEqual
- -isEqualTo
- -isLike
- == (built-in? not overrideable?)
- any others I missed?
What is the protocol for these methods? (deep or shallow comparison, etc…?) Which one should I be using to replace an operator==() that compares all its members?
isEqual:is likely what you want to override. Also ensure thathashreturns the same value for two objects that are equal.There isn’t really a protocol for comparison. Do whatever makes sense for your class. If you’re comparing all members in your
operator==()then that’d be deep comparison and yes, useisEqual:.