Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Boolean value <invalid>

The attached screen shot says it all: I have a valid true Bool, I negate it with the bang operator, and (Xcode tells me) I have an invalid value.

It appears that this "invalid" value does behave as if it were false. But really, wtf?

enter image description here

like image 908
Andrew Duncan Avatar asked Dec 15 '16 20:12

Andrew Duncan


People also ask

What is invalid Boolean value?

Detects when a program accesses a Boolean variable and its value isn't true or false.

How do you declare a Boolean in Swift?

Swift recognizes a value as boolean if it sees true or false . You can implicitly declar a boolean variable let a = false or explicitly declare a boolean variable let i:Bool = true .


1 Answers

I've had this issue in Xcode 8.3.1 and Swift 3.1 https://github.com/onmyway133/notes/issues/278

I tried

  • Clean build folder and delete derived data folder
  • Delete the app
  • Reset simulator
  • Restart Xcode
  • Restart Mac

But does not work. The workaround is to

let enabled = disable ? false : true
like image 161
onmyway133 Avatar answered Oct 11 '22 15:10

onmyway133