问题
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
.
回答1:
Apparently this is just a bug in swift playground and according to @Anton, printing the variables shows the correct value.
来源:https://stackoverflow.com/questions/34870929/swift-uint-behaviour