[英]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.