Programming in Swift: Functions & Types

Jan 4 2022 · Swift 5.5, iOS 15, Xcode 13

Part 3: Enumerations

23. Switch Statements

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 22. Challenge: Enumerations Next episode: 24. More Switch Statements

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 23. Switch Statements

Update Notes: This course was originally recorded in 2019. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

At this point, you’re familiar with a few different ways of controlling the flow of execution in your apps: if statements, while loops, and for loops. Now, you’ll learn about one more method of control flow: switch statements.

func getSeason(
(for month: Month) -> Season {

}
if month == .december
.december || month == .january || month == .february {

}
return .winter
switch 
switch month 
switch month {

}
case .december
case .december😺:
  return .winter
case .december, .january, .february:
  case .march:
    <#code#>
  case .april:
    <#code#>
  case .may:
    <#code#>
  case .june:
    <#code#>
  case .july:
    <#code#>
  case .august:
    <#code#>
  case .september:
    <#code#>
  case .october:
    <#code#>
  case .november:
    <#code#>
  }
case .march, .april, .may:
    return .spring
case .june, .july, .august:
    return .summer
case .september, .october, .november:
    return .autumn
getSeason(for: .august)