iiF*_*man 62 tuples switch-statement ios swift xcode6
有一个像这样的代码:
switch (indexPath.section, indexPath.row) {
case (0, 1...5): println("in range")
default: println("not at all")
}
Run Code Online (Sandbox Code Playgroud)
问题是我可以在第二元组值中使用多个区间吗?
对于非元组切换,它可以很容易地完成
switch indexPath.section {
case 0:
switch indexPath.row {
case 1...5, 8...10, 30...33: println("in range")
default: println("not at all")
}
default: println("wrong section \(indexPath.section)")
}
Run Code Online (Sandbox Code Playgroud)
我应该使用哪个分隔符来分隔元组内部的间隔,或者它不适用于元组开关,我必须在开关内使用开关?谢谢!
dre*_*wag 137
您必须在顶级列出多个元组:
switch (indexPath.section, indexPath.row) {
case (0, 1...5), (0, 8...10), (0, 30...33):
println("in range")
case (0, _):
println("not at all")
default:
println("wrong section \(indexPath.section)")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37450 次 |
| 最近记录: |