0Pricing
Swift Academy · Lesson

switch — exhaustiveness, ranges, tuples, where

Use powerful switch with exhaustive cases, numeric ranges, tuple matching, and where clauses.

Intro

switch in Swift is expressive and safe: it is exhaustive and supports ranges, tuples, and where clauses.

Basic switch

Switch can match strings and must be exhaustive via cases or default.

let fruit = "apple"
switch fruit {
case "apple": print("Good fiber")
case "banana": print("Potassium")
default: print("Tasty fruit")
}

All lessons in this course

  1. if/else basics
  2. switch — exhaustiveness, ranges, tuples, where
  3. Loops — for-in, while, repeat-while
← Back to Swift Academy