Updating an old app from swift 2.2 to swift 4. I have to use swift 3 as a stepping stone. I converted to 3 but come across the following error:
Binary operator '==' cannot be applied to operands of type 'IndexPath' and 'Int`
The code is:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if (indexPath as NSIndexPath).row == 0 || indexPath == 1 {
self.performSegue(withIdentifier: "NFL", sender: self)
}
if (indexPath as NSIndexPath).row == 1 {
self.performSegue(withIdentifier: "AFL", sender: self)
}
if (indexPath as NSIndexPath).row == 2 {
self.performSegue(withIdentifier: "FAI", sender: self)
}
if (indexPath as NSIndexPath).row == 3 {
self.performSegue(withIdentifier: "IPA", sender: self)
}
}
Why do I get this error in Swift 3 and not 2.2? I tried to force it into an "Int" but don't think I was going about it the right way.
indexPathcontainsrowandsectionyou need to specify if you want
indexPath.roworindexPath.sectionif you actually meant
indexPath.row, your full code should look like:Tips:
You don't need to cast to
NSIndexPathFor this comparison purpose, you should use a
switchstatement instead of manyifstatements.If
indexPath.row == 1it is going to performSegue twice with different results.