变量
- type inference
var swiftString = "swift is fun"
var hours = 24
var PI = 3.14
var swiftFun = true
var me = ("Mars", 11, "989791040@qq.com")
me.0 = "Mars"
me.1 = 11 - type annotation
var str: string
var x: int
常量
let minute = 30
let fireIsHot = true
整数
(u)int 8, (u)int 16, (u)int 32, (u)int 64.
通常用int or uint即可,swift编译器会根据目标平台把int or uint转换为对应的整数类型
浮点数
- float:精确到小数点后6位*
- double: 精确到小数点后15位
一般尽可能使用double表示浮点数类型 - 推断类型:
var four = 4
type(of:four) int.Type











网友评论