Skip to content

Instantly share code, notes, and snippets.

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