- Mastering macOS Programming
- Stuart Grimshaw
- 84字
- 2021-07-02 22:54:30
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.