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

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"
}
主站蜘蛛池模板: 张家港市| 新疆| 咸宁市| 霍山县| 崇州市| 个旧市| 梁山县| 西盟| 南昌县| 连南| 利辛县| 光山县| 泾阳县| 牡丹江市| 辽阳县| 乌审旗| 西林县| 黄浦区| 石棉县| 鸡西市| 玛多县| 阜阳市| 阳城县| 蚌埠市| 紫阳县| 巫山县| 锦州市| 蕉岭县| 贵定县| 广东省| 延庆县| 宝清县| 西充县| 龙岩市| 无棣县| 渭源县| 怀仁县| 温泉县| 白沙| 洛浦县| 巩义市|