目录索引
Point 11.
数值型字面量
代码事例:
let decimalInteger = 17 // 十进制的17let binaryInteger = 0b10001 // 二进制的17let octalInteger = 0o21 // 八进制的17let hexadecimalInteger = 0x11 // 十六进制的17
注解:
let decimalDouble = 17.2e0 // 十进制浮点数的17.2let hexadecimalDouble = 0x11.2p0 // 十六进制浮点数的17.125
let paddedDouble = 000123.456let oneMillion = 1_000_000let justOverOneMillion = 1_000_000.000_000_1
Point 12.
数值型类型转换
代码事例:
let twoThousand: UInt16 = 2_000let one: UInt8 = 1let twoThousandAndOne = twoThousand + UInt16(one)
注解:
let three = 3let pointOneFourOneFiveNine = 0.14159let pi = Double(three) + pointOneFourOneFiveNine
Point 13.
类型别名
代码事例:
typealias AudioSample = UInt16 // UInt16的类型别名被定义为AudioSamplevar maxAmplitudeFound = AudioSample.min // maxAmplitudeFound 现在是 0
注解:
Point 14.
布尔值
代码事例:
let orangesAreOrange = true // 值为真let turnipsAreDelicious = false // 值为假
注解:
Point 15.
元组
代码事例:
// http404Error 的类型是 (Int, String),值是 (404, "Not Found")let http404Error = (404, "Not Found")
注解:
let (statusCode, statusMessage) = http404Error// 输出 "The status code is 404"PRintln("The status code is /(statusCode)")// 输出 "The status message is Not Found"println("The status message is /(statusMessage)")
let (justTheStatusCode, _) = http404Error// 输出 "The status code is 404"println("The status code is /(justTheStatusCode)")
// 输出 "The status code is 404"println("The status code is /(http404Error.0)")// 输出 "The status message is Not Found"println("The status message is /(http404Error.1)")
let http200Status = (statusCode: 200, description: "OK")// 输出 "The status code is 200"println("The status code is /(http200Status.statusCode)")// 输出 "The status message is OK"println("The status message is /(http200Status.description)")
作者:清风抚柳 (DashGeng)
出处:http://www.VEVb.com/dashgeng/
新闻热点
疑难解答