Search code examples
swiftuint64uint32uint

Swift - UInt behaviour


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.


Solution

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

    enter image description here