Swift: Multiple intervals in single switch-case using tuple

后端 未结 1 1230
北荒
北荒 2021-01-30 19:53

Have a code like:

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

相关标签:
1条回答
  • 2021-01-30 20:36

    You have to list multiple tuples at the top level:

    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)")
    }
    
    0 讨论(0)
提交回复
热议问题