- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 123字
- 2021-07-02 23:54:26
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"
}
推薦閱讀
- 數(shù)據(jù)可視化:從小白到數(shù)據(jù)工程師的成長(zhǎng)之路
- 劍破冰山:Oracle開(kāi)發(fā)藝術(shù)
- 區(qū)塊鏈通俗讀本
- 軟件成本度量國(guó)家標(biāo)準(zhǔn)實(shí)施指南:理論、方法與實(shí)踐
- 數(shù)據(jù)驅(qū)動(dòng)設(shè)計(jì):A/B測(cè)試提升用戶體驗(yàn)
- Construct 2 Game Development by Example
- Instant Autodesk AutoCAD 2014 Customization with .NET
- 數(shù)據(jù)庫(kù)技術(shù)及應(yīng)用
- Python數(shù)據(jù)分析從小白到專(zhuān)家
- Hands-On System Programming with C++
- 數(shù)據(jù)庫(kù)原理與設(shè)計(jì)實(shí)驗(yàn)教程(MySQL版)
- 大數(shù)據(jù)時(shí)代系列(套裝9冊(cè))
- Scratch 2.0 Game Development HOTSHOT
- Hadoop大數(shù)據(jù)技術(shù)開(kāi)發(fā)實(shí)戰(zhàn)
- SQL必知必會(huì)(第5版)