Wildcard pattern

The wildcard pattern is a way of indicating “don’t care”. You can use this pattern to ignore a value.

Revisit the example you saw at the beginning of this chapter, where you wanted to check if a value was on the x-axis, for the (x, y, z) tuple coordinate:

if case (_, 0, 0) = coordinate {

// x can be any value. y and z must be exactly 0. print("On the x-axis") // Printed!

}

The pattern in this case condition matches any value of x component and exactly 0

for the y and z components.

results matching ""

    No results matching ""