Hashable にする最小限
swift
struct Test01: Identifiable, Hashable {
var id = UUID()
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.id == rhs.id
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
複数キーがある場合はこんな感じ
swift
struct AreaNode: Hashable {
var name: String
var type: AreaNodeType
static func == (lhs: Self, rhs: Self) -> Bool {
lhs.name == rhs.name
&& lhs.type == rhs.type
}
func hash(into hasher: inout Hasher) {
hasher.combine(name)
hasher.combine(type)
}
}