相同和平等的区别?

Dav*_*vid 0 objective-c

我无法理解两个相同的事物和两个相同的事物之间的概念.令我困惑的是声明"两个对象可以是相同的,这意味着它们是相同的.但是,两个相等的对象并不相同." 请有人帮我理解差异吗?谢谢.

jac*_*ash 5

在objective-c,略微伪代码......

NSString * a = @"hello";
NSString * b = @"hello";

a == a    //they are identical (the same object)
[a isEqualToString:a]; //they are equal.
a != b    //Even though the string contents are the same they are not the same object.
[a isEqualToString:b]; // they aren't identical but they are equal.
Run Code Online (Sandbox Code Playgroud)

关于这个主题的一篇很长很好的博客文章,请看这个

http://www.karlkraft.com/index.php/2008/01/07/equality-vs-identity/

  • 我应该知道这一点,但我在消息.是不是==和"isEqual"是一回事? (2认同)