输入' Int'不符合协议' BooleanType'

时间:2015-02-19 17:57:54

标签: swift

我对此声明做错了什么? currentRow是一个NSIndexPath

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

我得到的错误是:

  

类型'Int'不符合协议'BooleanType'

2 个答案:

答案 0 :(得分:6)

如果要检查,如果currentRow和indexPath都是5,则不能使用if语句。将其更改为:

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

或:

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

如果您想检查indexPath是否nil,请检查indexPath是否为0

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

答案 1 :(得分:1)

这是因为您尝试检查非可选indexPath.row是否已设置。

如果您想将indexPath.row检查为零,请添加明确的检查:

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

与Objective-C不同,它允许您在没有显式条件的情况下执行nil和零检查,Swift期望显式条件,或使用由可选类型实现的BooleanType协议执行检查。

相关问题