// switch 可以判断除整型之外的其他类型
/** switch
switch 可以判断除整型之外的其他类型
`fallthrough` 关键字 表示可以继续向下执行
*/
let point = (0, 0)
switch point {
case (0, 0):
print("orign")
fallthrough
case (_, 0):
print("X")
case (0, _):
print("Y")
default:
print("point")
}
// where 添加判断条件
let point = (1, 3)
switch point {
case let (x, y) where x == y:
print("X == Y")
case let (x, y) where x == -y:
print("X == Y")
case (_, _):
print("point")
}
// if case 判断条件 where
let age = 19
if case 10...19 = age {
print("age is 19")
}
if case 10...19 = age, age >= 18 {
print("age is 19 , teenager")
}
网友评论