Currently, we have the following enum.
enum Animal : Equatable {
case dog(String)
case cat(Int)
}
If we want to compare enum type and its associate value, we can simply do this.
let dog0 = Animal.dog("mimi")
let dog1 = Animal.dog("hihi")
if (dog0 == dog1) {
print("same dog type and same name")
} else {
print("not same dog")
}
not same dog will be printed.
What if, we also want to have the ability, to compare enum type only and ignore its associated value?
if (???) {
print("same dog type (might be different name)")
} else {
print("not same dog")
}
May I know, what kind of technique we can use?