0Pricing
Swift Academy · Lesson

Enums with Power basics

Define enums with raw or associated values, use switch for exhaustive matching, and model states with them.

Intro

Swift enums go beyond simple constants. They can have raw values or associated values and work with exhaustive switch statements.

Raw values

Raw values assign a constant value to each case, e.g., String or Int.

enum Direction: String {
    case north = "N"
    case south = "S"
}
print(Direction.north.rawValue)

All lessons in this course

  1. Enums with Power basics
  2. Powerful switch with pattern matching
  3. Finite state modeling
← Back to Swift Academy