hash isEqual

Posted zzfx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hash isEqual相关的知识,希望对你有一定的参考价值。

hash

Returns an integer that can be used as a table address in a hash table structure.

 

If two objects are equal (as determined by the isEqual(_:) method), they must have the same hash value. This last point is particularly important if you define hash in a subclass and intend to put instances of that subclass into a collection. 

If a mutable object is added to a collection that uses hash values to determine the object’s position in the collection, the value returned by the hash method of the object must not change while the object is in the collection. Therefore, either the hash method must not rely on any of the object’s internal state information or you must make sure the object’s internal state information does not change while the object is in the collection. Thus, for example, a mutable dictionary can be put in a hash table but you must not change it while it is in there. (Note that it can be difficult to know whether or not a given object is in a collection.)

以上是关于hash isEqual的主要内容,如果未能解决你的问题,请参考以下文章

iOS之如何实现isEqual的重写

第八条:理解“对象等同性”这一概念

iOS 一个对象的等同性

如何从URL获取片段标识符(hash#之后的值)?

我应该如何测试 BDD 中值对象类型的“isEqual”方法?

indexAtPosition、urlRequest.url!.isEqual 的 swift 3 等效项