Swift-UInt行为

扫码查看
本文介绍了Swift-UInt行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用我的64位Mac(Macbook Pro 2009),Xcode操场上的这段代码表现得很奇怪:

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.

var3设置为-1会产生错误.但是在声明行中,它等于-1.

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

推荐答案

显然,这只是快速操场中的一个错误,根据@Anton的说法,打印变量会显示正确的值.

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

这篇关于Swift-UInt行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:03
查看更多