iOS ● ● ○ Swift 6

Kodebits Day 51: Enum Associated Values

Jul 3 2026
Practice enums with a short swift challenge.

What does this print?

enum Result {
  case success(Int)
  case failure(String)
}
let r = Result.success(42)
switch r {
case .success(let val):
  print(val)
case .failure(let msg):
  print(msg)
}


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

42

Explanation:

Associated values let enums carry data; pattern matching extracts it.

[/spoiler]


Further Reading