I'm reading Set
You use a set instead of an array when you need to test efficiently for membership and you aren’t concerned with the order of the elements in the collection, or when you need to ensure that each element appears only once in a collection.
Basically Set
ensures uniqueness, it has some methods and relies on Hashable
Use the contains(_:) method to test whether a set contains a specific element.
Use the subtracting(_:) method to create a new set with the elements of a set that are not also in another set or sequence
But 2 different objects can have the same hashValue
, like in this post Swift Hashable
Do not assume that two instances of a type with the same hash value are equal. Depending on how we compute the hash value we can get collisions where two different instances share the same hash value. The Hashable protocol only needs the reverse - two equal instances have the same hash value.
So what if 2 objects have the same hashValue
, and Set
only saves 1, then we have the problem?