I have a struct
, Student that conforms to Hashable
protocol but I am getting an error for the hash(into:)
method.
struct Student: Hashable{
let studentID: Int
let name: String
init(studentID id:Int, andName name: String){
studentID = id
self.name = name
}
func hash(into hasher: inout Hasher){
hasher.combine(bytes: ObjectIdentifier(self.Type)) //giving compile-time error
}
static func == (lhs: Self, rhs: Self) -> Bool{
return (lhs == rhs)
}
}
I am getting error for the function hash(into:)
. As Student is a struct not class, I am confused on how to implement the required hash(into:)
function. Can anyone please help me.