Should you use 'isEqual' or '=='?

后端 未结 2 1746
你的背包
你的背包 2020-12-04 00:06

I saw a couple of questions here on SO, with ansers including the function isEqual: instead of the standard ==.

So far, I have only learned

2条回答
  •  萌比男神i
    2020-12-04 00:37

    isEqual will compare objects according to the method written for the receiver object

    == compares the addresses of Objects (or their values for C type variables like ints

    This means for say NSStrings == compares the address but isEquals: will look at the values of the string objects and so does something similar to strcmp

    Note that many strings are interned so that their addresses are the same if their data is the same so == can appear to work in test cases.

提交回复
热议问题