iOS ● ● ○ Swift 6

Kodebits Day 28: Enum Associated Values

May 24 2026
Practice enums with a short swift challenge.

What does this print?

enum Result {
  case ok(Int)
  case err(String)
}
let r = Result.ok(42)
if case .ok(let v) = r {
  print(v)
}


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

42

Explanation:

Pattern matching with `if case` extracts the associated value from the enum case.

[/spoiler]


Further Reading