Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Tuple matching

If we are dealing with tuples in a switch statement, we can test against them too:

let b = 0 
let c = 1
let t = (b, c)

switch t {
case (0,0):
print("cannot divide by a or b")
case (0,_):
print("cannot divide by a")
case (_,0):
print("cannot divide by b")
default:
print("can divide by both a and b")
}

Note how the underscore denotes a value in which we are not interested, as is the case with for in loops.