switch that checks NSIndexPath's row and section

Viewed 7776

I would like to set a switch statement that checks for a value if NSIndexPath. NSIndexPath is a class and it consists(among other things) of section and row (indexPath.row, indexPath.section)

this is how I would formulate an if statement to check for a row and a section at the same time:

if indexPath.section==0 && indexPath.row == 0{
//do work
}

What is swift switch translation for this?

3 Answers

An Alternative way is to combine switch with if case

switch indexPath.section {
case 0:
    if case 0 = indexPath.row {
        //do somthing
    } else if case 1 = indexPath.row  {
          //do somthing
        // other possible cases
    } else { // default
        //do somthing
    }
case 1:
// other possible cases
default:
    break
}
Related