Last active
April 19, 2020 16:56
Hasher, how it works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using hasher. Actually, you will never use it directly. | |
var hasher = Hasher() | |
hasher.combine("Hello") | |
hasher.combine("World") | |
hasher.combine(2020) | |
let hashValue = hasher.finalize() | |
// This is the correct way to implement Hashable. | |
extension YourStruct: Hashable { | |
func hash(into hasher: inout Hasher) { | |
hasher.combine("Hello") | |
hasher.combine("World") | |
hasher.combine(2020) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment