//什么时候可以不添加 default:
enum en {
case ddd
case aaa
}
let type: en = .aaa
switch type {
case .aaa:
break
case .ddd:
break
}
let vegetable = “red pepper”
switch vegetable {
case “celery”:
let vegetableComment = "Add some raisins and make ants on a log."
case “cucumber”, “watercress”:
let vegetableComment = "That would make a good tea sandwich."
case let x where x.hasSuffix(“peper”)://后缀
let vegetableComment = "Is it a spicy \(x)?"
case let x where x.hasPrefix(“rdd”)://前缀
let vegetableComment = "Is it a spicy \(x)?"
case let x where x.contains(“pe”)://包含
let vegetableComment = "Is it a spicy \(x)?"
default:
break
}