Last active
April 19, 2020 16:56
-
-
Save FabP93/f07c4a30cdd68f79af4745a71b833c0f to your computer and use it in GitHub Desktop.
Hasher, how it works
This file contains 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