Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

Not sure what I'm doing wrong here, but here's the trivial code that's breaking:

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

This gives me:

'Int' is not convertible to 'Bool'

What is wrong?

like image 468
randombits Avatar asked Dec 10 '22 13:12

randombits


1 Answers

Unlike in C where you can write...

if (x) { }

... which is really a non-zero check:

if (x != 0) { }

You must test for a boolean condition in Swift. Add != 0 to your statement:

if 10 & (1<<18) != 0 {
    return
}
like image 158
Code Different Avatar answered Feb 01 '23 22:02

Code Different