swift 基本数据类型

变量和常量

使用关键字 let 来声明常量

使用关键字 var 来声明变量

常量只能赋值一次

常量的值不要求在编译时确定,但在使用之前必须赋值一次

常量和变量初始化之前都不能使用

定义常量,变量,函数名的标识符几乎可以用任意字符

常见数据类型

值类型 (value type)

枚举 (enum) optional

结构体 (struct) Bool Int Float Double Character String Array Dictionary Set

整数类型 

Int8,Int16,Int32,Int64  ,  UInt8,UInt16,UInt32,UInt64   (UnsignedInteger)

在32位平台上Int等价于Int32,在64位平台上Int等价于Int64

整数最值: UInt8.max   Int16.min    Int 最值 是结构体中的属性

浮点类型

Float: 32位,精度只有6位; Double,64位,精度至少15位

字面量

let bool = true ; let string = "字符串";  let character: Character: = "字符"

let intDecimal = 10;  let doubleDecimal = 100.0;

let array = [1,3,5,7] ; let dictionary = ["width":100, "height": 150]

元祖

let http404Error = (404, "Not Found")

print("The status code is \(http404Error.0)")

引用类型 (reference type)

类 (class)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容