Sam Luther
Sam Luther

Reputation: 1190

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

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'

Upvotes: 4

Views: 2672

Answers (2)

Christian
Christian

Reputation: 22343

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 {

Upvotes: 6

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726499

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.

Upvotes: 1

Related Questions