1

Using my 64 bit Mac (Macbook Pro 2009), this code in Xcode playground is acting weird:

let var1 = UInt32.max // 4,294,967,295
let var2 = UInt64.max // -1 --> why?
var var3: UInt = UInt.max // -1 --> why?
var3 = -1 // generates an error. 

setting var3 to -1 should generate an error. But in the declaration line, it became equal to -1.

Milad
  • 1,239
  • 3
  • 19
  • 37
  • Are you saying the playground allows you to write `var3 = -1` without reporting an error? – Cristik Jan 19 '16 at 07:47
  • @Cristik No, as I've written in the 4th line of the code, it does generate an error. But I'm not sure why the compiler sets it to `-1` in line 3. – Milad Jan 19 '16 at 08:01
  • 2
    I think it's just a bug in prayground's representation of unsigned 64bit integer, which it probably interprets as a signed one. If you add `print(var2)` then you will see a correct number printed. – 0x416e746f6e Jan 19 '16 at 08:12

1 Answers1

2

Apparently this is just a bug in swift playground and according to @Anton, printing the variables shows the correct value.

enter image description here

Milad
  • 1,239
  • 3
  • 19
  • 37