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:
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 that hash
returns 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, use isEqual:
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.