课程来自慕课网liuyubobobo老师
基本类型
- 常量、变量和声明
let num = 9 // 常量
var index = 3 // 变量
let str: String = "Hello" // 类型声明
- 整型
let aInt: Int = 8 // 整型
let aUInt: UInt = 90 // 无符号整型
- 浮点数和类型转换
let aFlort: Float = 3.1415926 // 3.141593
let aDouble: Double = 3.1415926 // 3.1415926
let x: UInt16 = 100
let y: UInt8 = 8
let m = x + UInt16(y) // 108
- 布尔类型和简单的if语句
let aTure = true
let aFalse: Bool = false
if aTure {
print("true")
}else {
print("false")
}
- 元组(Tuple)
let point = (2,3)
point.0 // 2
point.1 // 3
let point2 = (x: 4, y: 1)
point2.x // 4
point2.y // 1
let point3: (x: Int, y: Int) = (5,4)
point3.x // 5
point3.y // 4
let httpRespense: (Int, String) = (200,"OK")
let (statusCode, _) = httpRespense
statusCode // 200
- 其他(变量名、print和注释)
let name = "Owen"
print("Hello, \(name)") // Hello,Owen
/*
多行注释
*/
网友评论