Skip to content

Instantly share code, notes, and snippets.

@FabP93
Created April 19, 2020 17:02
Show Gist options
  • Save FabP93/1b3da0036b16fb114904a60151a067f6 to your computer and use it in GitHub Desktop.
Save FabP93/1b3da0036b16fb114904a60151a067f6 to your computer and use it in GitHub Desktop.
Hashable example
struct Key {
let id: Int
let title: String
}
extension Key: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(self.id)
}
}
var dict = [Key: Int]()
let key1 = Key(id: 1, title: "Key1")
let key2 = Key(id: 2, title: "Key2")
dict[key1] = 1058
dict[key2] = 368
print(dict.count) // 2
print(key1 == key2) // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment