Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Int' does not conform to protocol 'BooleanType'

Tags:

swift

What am I doing incorrectly with this statement? currentRow is a NSIndexPath

  override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row && currentRow?.row == 5 {
        return  300
    }
    return 70

The error I get is:

Type 'Int' does not conform to protocol 'BooleanType'

like image 467
Sam Luther Avatar asked Mar 16 '23 23:03

Sam Luther


2 Answers

If you want to check, if your currentRow and indexPath are both 5 you can't use an if-statement like that. Change it to:

 if indexPath.row == currentRow?.row  && currentRow == 5 {

or:

 if indexPath.row == 5  && currentRow?.row == 5 {

If you want to check if indexPath is nil check if the indexPath is 0

if indexPath.row != 0 && currentRow?.row == 5 {
like image 107
Christian Avatar answered May 30 '23 13:05

Christian


This happens because you are trying to check a non-optional indexPath.row for being set.

If you would like to check indexPath.row for zero, add an explicit check:

if indexPath.row != 0 && currentRow?.row == 5 {
    return  300
}

Unlike Objective-C, which lets you do nil and zero checks without an explicit condition, Swift expects an explicit condition, or performs the check using BooleanType protocol implemented by optional types.

like image 28
Sergey Kalinichenko Avatar answered May 30 '23 11:05

Sergey Kalinichenko