Hashable and hash(into:)
Enable use as dictionary keys and set members.
What Is Hashable?
Hashable builds on Equatable and provides a hash value. It is required to use a type as a Set element or a Dictionary key.
Automatic Hashable
Like Equatable, structs and enums with Hashable members get it synthesized:
struct Point: Hashable {
let x: Int
let y: Int
}
let set: Set<Point> = [Point(x: 0, y: 0), Point(x: 0, y: 0)]
print(set.count) // 1 -- duplicate collapsedAll lessons in this course
- Synthesized Equatable
- Hashable and hash(into:)
- Comparable and Sorting
- Custom Equality Semantics