How do I compare objects in Objective-C?

后端 未结 4 1737
长发绾君心
长发绾君心 2020-12-05 18:28

How do I compare two objects of a custom class? My idea was to add an additional method to the class in which I can compare the current object with another object of the sam

4条回答
  •  一整个雨季
    2020-12-05 18:50

    The standard way is to override - (BOOL)isEqual:(id)anObject and - (NSUInteger)hash.

    You should read the documentation for NSObject protocol and this SO question has some interesting answers on how to write your hash method.

提交回复
热议问题