Swift - UInt behaviour

人走茶凉 提交于 2019-12-24 16:07:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!