Swift 数据类型

Swift 的数据类型很有意思,即便是基本类型其实也是结构体。

值类型 枚举(enum) Optional
值类型 结构体(struct) Bool、Int、Float、Double、character、
String、Array、Dictionary、Set
引用类型(reference type) 类(class)
常见数据类型
  • 整数类型:Int8、Int16、Int32、Int64、UInt8、UInt16、UInt32、UInt64
  • 在32bit平台:Int 等价于 Int32;在 64bit 平台,Int 等价于 Int64
  • 整数的最值:UInt8.max、Int16.min
  • 一般情况下,建议直接使用 Int
  • 浮点类型:Float,32 位,精度只有 6 位;Double,64 位,精度至少 15 位

Leave a Reply

Your email address will not be published. Required fields are marked *