2017-06-11 83 views

回答

0
  • Int一個有符號的整數值類型。在32位平臺上,Int的大小與Int32的大小相同,在64位平臺上,Int的大小與Int64的大小相同。
  • UInt8一個8位無符號整數值類型。

所以具有前綴U的原始數據類型是具有相同位大小的無符號版本。這意味着它們不能存儲負數。

let u: UInt8 = 8 
print(u) // 8 

let u: UInt8 = -8 
print(u) // error: negative integer '-8' overflows when stored into unsigned type 'UInt8' 

對於轉換問題結帳this答案。

相關問題