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

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"
}
主站蜘蛛池模板: 南郑县| 句容市| 若尔盖县| 万山特区| 禹州市| 郧西县| 十堰市| 甘洛县| 吉林市| 平谷区| 平江县| 清涧县| 安达市| 西峡县| 都江堰市| 阳城县| 龙游县| 老河口市| 雅安市| 沂南县| 桂阳县| 巴塘县| 临湘市| 平南县| 阆中市| 商丘市| 镇赉县| 芮城县| 游戏| 集安市| 塔城市| 遂溪县| 灵璧县| 肃宁县| 临沧市| 南岸区| 平度市| 长阳| 疏附县| 钟山县| 布尔津县|