简体   繁体   中英

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'

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 {

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM