Created
April 19, 2020 17:02
-
-
Save FabP93/1b3da0036b16fb114904a60151a067f6 to your computer and use it in GitHub Desktop.
Hashable example
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
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