swift 关于 switch 笔记

来源:互联网 发布:可变数据 编辑:程序博客网 时间:2024/05/09 10:48

//什么时候可以不添加 default:

enum en {

case dddcase 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

}

0 1