简体   繁体   English

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

[英]Type 'Int' does not conform to protocol 'BooleanType'

What am I doing incorrectly with this statement? 我对这个陈述做错了什么? currentRow is a NSIndexPath currentRow是一个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' 类型'Int'不符合协议'BooleanType'

If you want to check, if your currentRow and indexPath are both 5 you can't use an if-statement like that. 如果要检查,如果currentRow和indexPath都是5 ,则不能使用if语句。 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 如果要检查indexPath是否为nil请检查indexPath是否为0

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

This happens because you are trying to check a non-optional indexPath.row for being set. 发生这种情况是因为您正在尝试检查非可选的indexPath.row是否已设置。

If you would like to check indexPath.row for zero, add an explicit check: 如果您想检查indexPath.row为零,请添加一个显式检查:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“Int”不符合协议“BooleanType”? - Type 'Int' does not conform to protocol 'BooleanType'? 类型&#39;()&#39;不符合协议&#39;BooleanType&#39; - Type '()' does not conform to protocol 'BooleanType' 类型HalfOpenInterval <T> 不符合协议BooleanType - Type HalfOpenInterval<T> does not conform to protocol BooleanType 类型“ AnyObject”不符合协议“ BooleanType” - Type 'AnyObject' does not conform to protocol 'BooleanType' 类型“NSPersistentStore”在swift中不符合协议“BooleanType” - Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift 类型'Boolean'不符合协议'BooleanType' - Type 'Boolean' does not conform to protocol 'BooleanType' 游乐场执行失败: <EXPR> :15:33:错误:类型&#39;Int&#39;不符合协议&#39;BooleanType&#39; - Playground execution failed: <EXPR>:15:33: error: type 'Int' does not conform to protocol 'BooleanType' 将Objective-C转换为Swift-错误:类型&#39;Int&#39;不符合协议&#39;BooleanType&#39; - Translating Objective-C to Swift - Error: Type 'Int' does not conform to protocol 'BooleanType' 内联if语句在void返回闭包中改变inout参数,奇怪的错误(错误:类型&#39;Int1&#39;不符合协议&#39;BooleanType&#39;) - Inline if statement mutating inout parameter in a void return closure, weird error (Error: type 'Int1' does not conform to protocol 'BooleanType') 类型“()”未确认协议:“ BooleanType” - Type '()" does not confirm to protocol: 'BooleanType'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM