Swift语言中是否只有var和let两种数据类型?

2 min read

Swift语言中并不是只有var和let两种数据类型。var和let是用来声明变量和常量的关键字,而数据类型包括但不限于以下几种:

  • 整数类型:Int、UInt、Int8、UInt8、Int16、UInt16、Int32、UInt32、Int64、UInt64
  • 浮点数类型:Float、Double
  • 布尔类型:Bool
  • 字符串类型:String
  • 字符类型:Character
  • 可选类型:Optional
  • 数组类型:Array
  • 字典类型:Dictionary
  • 元组类型:Tuple

除此之外,Swift还支持枚举类型、结构体类型、类类型以及函数类型等。