iOS ● ● ○ Swift 6

Kodebits Day 40: Pattern Match Tuple

Jun 14 2026
Practice pattern matching with a short swift challenge.

What does this print?

let point = (x: 4, y: 0)
switch point {
case (0, 0):
  print("Origin")
case (_, 0):
  print("X-axis")
case (0, _):
  print("Y-axis")
default:
  print("Other")
}


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

X-axis

Explanation:

Pattern matching uses wildcards to match tuples where y is 0.

[/spoiler]


Further Reading