This means that case labels with multiple patterns cannot declare variables.
It is allowed:
let somePoint = (1, 1)
switch somePoint {
case (0, _),
(_, 0):
println("(\(somePoint.0), \(somePoint.1)) is on an axis")
default:
println("(\(somePoint.0), \(somePoint.1)) is not of an axis")
}
This is also allowed:
let somePoint = (1, 1)
switch somePoint {
case (0, let y):
println("(0, \(y)) is on an axis")
case (let x, 0):
println("(\(x), 0) is on an axis")
default:
println("(\(somePoint.0), \(somePoint.1)) is not of an axis")
}
However, this is prohibited:
let somePoint = (1, 1)
switch somePoint {
case (0, let y),
(let x, 0):
println("(\(x), \(y)) is on an axis")
default:
println("(\(somePoint.0), \(somePoint.1)) is not of an axis")
}
The above error:
error: 'case' labels with multiple patterns cannot declare variables
source
share