官术网_书友最值得收藏!

Switch

Swift provides the switch statement to compare a value against different matching patterns. The related statement will be executed once the pattern is matched. Unlike most other C-based programming languages, Swift does not need a break statement for each case and supports any value types. Switch statements can be used for range matching, and where clauses in switch statements can be used to check for additional conditions. The following example presents a simple switch statement with additional conditional checking:

let aNumber = "Four or Five" 
switch aNumber {
case "One":
let one = "One"
case "Two", "Three":
let twoOrThree = "Two or Three"
case let x where x.hasSuffix("Five"):
let fourOrFive = "it is \(x)"
default:
let anyOtherNumber = "Any other number"
}
主站蜘蛛池模板: 托克逊县| 合作市| 峨边| 文水县| 白朗县| 南安市| 澄江县| 桦川县| 宜黄县| 民乐县| 中阳县| 洛阳市| 新营市| 乌拉特前旗| 宽甸| 靖安县| 苍南县| 石渠县| 屏东县| 梓潼县| 弥勒县| 绵竹市| 额济纳旗| 南汇区| 历史| 贵德县| 绵竹市| 曲麻莱县| 从江县| 荔浦县| 慈利县| 高密市| 昌图县| 尼木县| 洛宁县| 金沙县| 法库县| 和田县| 吉首市| 湘西| 丰顺县|