目录索引
清风注解-Swift程序设计语言
Point 11.
数值型字面量
代码事例:
let decimalInteger = 17 // 十进制的17 let binaryInteger = 0b10001 // 二进制的17 let octalInteger = 0o21 // 八进制的17 let hexadecimalInteger = 0x11 // 十六进制的17
注解:
let decimalDouble = 17.2e0 // 十进制浮点数的17.2 let hexadecimalDouble = 0x11.2p0 // 十六进制浮点数的17.125
let paddedDouble = 000123.456 let oneMillion = 1_000_000 let justOverOneMillion = 1_000_000.000_000_1
Point 12.
数值型类型转换
代码事例:
let twoThousand: UInt16 = 2_000 let one: UInt8 = 1 let twoThousandAndOne = twoThousand + UInt16(one)
注解:
let three = 3 let pointOneFourOneFiveNine = 0.14159 let pi = Double(three) + pointOneFourOneFiveNine
Point 13.
类型别名
代码事例:
typealias AudioSample = UInt16 // UInt16的类型别名被定义为AudioSample var 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.cnblogs.com/dashgeng/
本文首发博客园,版权归作者所有,欢迎转载! 未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接, 否则保留追究法律责任的权利。