How to compare if two objects are really the same object?

前端 未结 4 548
感情败类
感情败类 2020-12-08 11:57

I want to compare if an variable A represents the same object as variable B does.

Could I do that with the == operator?

Or what else is this exactly looking

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 12:16

    [objectA isEqual:objectB] is usually a good choice. Note that some classes may have more specialized equality functions. (isEqualToString: et.al.) These generally test not if they are the same object, but if the objects are equal, which is a distinct concept. (Two string objects can be equal, even if they don't have the same memory address.)

提交回复
热议问题