Spot the bug
A Set ends up holding both "Swift" and "swift". Tap the line that breaks the Hashable contract.
struct Tag: Hashable {let name: Stringstatic func == (lhs: Tag, rhs: Tag) -> Bool {lhs.name.lowercased() == rhs.name.lowercased()}func hash(into hasher: inout Hasher) {hasher.combine(name)}}
Hint 1 of 1
Do equal values produce equal hashes here?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 7
hasher.combine(name)
Line 7 hashes the original string, but == compares lowercased names. Equal tags then get different hashes. Hash name.lowercased() instead.