Andrew Duncan
Andrew Duncan

Reputation: 3753

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

Upvotes: 11

Views: 1159

Answers (3)

JerryZhou
JerryZhou

Reputation: 5166

Got the same issue, with correct value for add code like print(theBoolValue).

But when use p in swift command line. Or just check the value in debug stack, the value become <invalid>(Oxfe).

Upvotes: 0

onmyway133
onmyway133

Reputation: 48085

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

Upvotes: 1

Andreas
Andreas

Reputation: 2715

I'm no LLVM expert but I wouldn't be surprised about this behavior at all, unless optimization is set to Onone in which case it should have left your code alone. The intermediate variable is just asking to be optimized away, after all.

Upvotes: 0

Related Questions