April 2017
Intermediate to advanced
316 pages
9h 33m
English
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 ...Read now
Unlock full access