Swift:使用元组在单个开关情况下的多个间隔

有一个像这样的代码:

switch (indexPath.section, indexPath.row) { case (0, 1...5): println("in range") default: println("not at all") } 

问题是我可以在第二个元组值中使用多个区间?

对于非元组切换它可以很容易地完成

 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)") } 

我应该使用哪个分隔符来分隔元组内的间隔,或者它不会为元组开关工作,而且我必须使用开关内部的开关? 谢谢!

你必须在顶层列出多个元组:

 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)") }