So I have this struct:
struct ListAction: Hashable {
let label: String
let action: (() -> Void)? = nil
let command: Command? = nil
}
But I get an error on the line it's declared on saying Type 'ListAction' does not conform to protocol 'Hashable'
.
I can get rid of the error if I remove the line defining the action
constant but I don't want to remove that line permanently.
I'm using Swift 5.1.
Supply your own implementation for Hashable
by overriding hash(into:)
and call combine
on all the relevant properties.
struct ListAction: Hashable {
static func == (lhs: ListAction, rhs: ListAction) -> Bool {
return lhs.label == rhs.label && lhs.command == rhs.command
}
func hash(into hasher: inout Hasher) {
hasher.combine(label)
hasher.combine(command)
}
let label: String
let action: (() -> Void)? = nil
let command: Command? = nil
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With