gpt4 book ai didi

swift 3 : Int is not convertible to Bool in bitwise operation

转载 作者:行者123 更新时间:2023-11-30 12:22:17 25 4
gpt4 key购买 nike

不确定我在这里做错了什么,但这是破坏的简单代码:

if 10 & (1<<18) {
return
}

这给了我:

'Int' is not convertible to 'Bool'

出了什么问题?

最佳答案

与 C 不同,你可以写...

if (x) { }

...这实际上是一个非零检查:

if (x != 0) { }

您必须在 Swift 中测试 bool 条件。将 != 0 添加到您的语句中:

if 10 & (1<<18) != 0 {
return
}

关于 swift 3 : Int is not convertible to Bool in bitwise operation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com