Has*_*tax 7 enums switch-statement swift
如果我在枚举中设置了我的案例,我可以在switch语句中调用多个这样的案例吗?又名case .a, .b: return true
enum myLetters {
case a
case b
case c
var myCondition: Bool {
switch self {
case .a, .b: return true
case .c: return false
default: return false
}
}
}
Run Code Online (Sandbox Code Playgroud)
Mo *_*eed 14
是的,看看雨燕的文档上switch发言.
为了达到你想要的效果,你需要检查当前的值myLetters:
var myCondition: Bool {
switch self {
case .a, .b: return true
case .c: return false
}
}
Run Code Online (Sandbox Code Playgroud)