Example with a tuple of switch/case statements in Swift
Forums:
let point = (5, 5)
switch (point) {
case (0, 0):
str = "(0, 0) point"
case (_, 1):
str = "(\(point.0), 1) point"
case (1, let y):
str = "(1, \(y)) point"
case (let x, let y) where x == y:
str = "(\(x), \(y)) point"
default:
str = "other point"
}
//str is (5, 5) point
- Log in to post comments