0

I have the following line of code from swift 1.1.

Now that I've upgraded (currently only to swift 1.2) I'm getting a runtime error on the following line:

let myBool = parseObject["myBoolField"] as? Bool ?? false

Has something changed with newer versions of Swift that change the way you use in casts?

Shouldn't this line never fail and always at least resolve to myBool = false ?

Alvaro Silvino
  • 9,441
  • 12
  • 52
  • 80
nwales
  • 3,521
  • 2
  • 25
  • 47
  • your code should work correctly. What is the message error? – Duyen-Hoa Oct 02 '15 at 15:07
  • I'm getting EXC_BAD_ACCESS errors where there were none before. parseObject is non nil. Puzzling. What I can confirm is that myBoolField does not exist on the object. This is sometimes expected, hence the ?? false fallback. – nwales Oct 02 '15 at 15:20
  • You can try optional chaining to obtain your "myBoolField": `let myBool = parseObject["myBoolField"]?.boolValue ?? false` – Duyen-Hoa Oct 02 '15 at 15:29
  • The code above gives an error: operand of postfix '?' should have optional type; type is AnyObject – nwales Oct 02 '15 at 15:37
  • Could this be related to this issue? http://stackoverflow.com/questions/28953306/pfobject-does-not-have-a-member-named-subscript – nwales Oct 02 '15 at 15:42

0 Answers0