enum StringCase:String {
case One = "One"
case Two,Three,Four,Five
func discription() -> String {
switch self {
case .One:
return "One"
case .Two:
return "Two"
case .Three:
return "Three"
case .Four:
return "Four"
case .Five:
return "Five"
}
}
}
上面的写法是正确的,编译不会报错,因为switch对所有的case做出了列举
下面的写法是错误的,编译会报错,因为switch没有所有的case做出列举,需要添加default分支
enum StringCase:String {
case One = "One"
case Two,Three,Four,Five
func discription() -> String {
switch self {
case .One:
return "One"
case .Two:
return "Two"
case .Three:
return "Three"
case .Four:
return "Four"
}
}
}