如果在swift中为枚举设置了关联值.
enum Country {
case China(city: String)
case Japan(city: String)
case Singapore
}
那么直接判断相等是错误的
let sig = Country.Singapore
if sig == Country.Singapore {
//...
}
要这样判断相等
let sig = Country.Singapore
if case Country.Singapore = sig {
//...
}
let gz = Country.Cina(city: "GuangZhou")
if case Country.Cina(city: "GuangZhou") = gz {
//...
}