I'm trying to make my struct Card conform to protocol Hashable(for dictionary), but for some reason Xcode does not yelling at me with red error like "Type 'Card' does not conform to protocol 'Hashable'. I don't understand why. I want Xcode to add protocol stubs.
import Foundation
struct Card : Hashable {
var isFaceUp = false
var isMatched = false
var identifier : Int
private static var identifierFactory = 0
private static func getUniqueIdentifier() -> Int {
Card.identifierFactory += 1
return Card.identifierFactory
}
init() {
identifier = Card.getUniqueIdentifier()
}
}
Hashable, the code you share does not raise an error, - Ömer Faruk ÖztürkCardas key of dictionary like[Card: String]as you wrote. It should work without any modification. Where do you get the error:Type 'Card' does not conform to protocol 'Hashable? - Ömer Faruk Öztürk