Swift switch statement

let somePoint = (1, 1)
switch somePoint {
case (0, 0):
    println("(0, 0) is at the origin")
case (_, 0):
    println("((somePoint.0), 0) is on the x-axis")
case (0, _):
    println("(0, (somePoint.1)) is on the y-axis")
case (-2...2, -2...2):
    println("((somePoint.0), (somePoint.1)) is inside the box")
    println("((somePoint.0), (somePoint.1)) is outside of the box")
// prints "(1, 1) is inside the box"

I just started to learn Swift on Apple’s developer website and came across a syntax confusion. What does the .0 mean in (somePoint.0)?

Is it always needed when there is a _ in every case and in every switch-statement?

Source: syntax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.