目錄索引
清風(fēng)注解-Swift程序設(shè)計(jì)語(yǔ)言
Point 11.
數(shù)值型字面量
代碼事例:
let decimalInteger = 17 // 十進(jìn)制的17let binaryInteger = 0b10001 // 二進(jìn)制的17let octalInteger = 0o21 // 八進(jìn)制的17let hexadecimalInteger = 0x11 // 十六進(jìn)制的17
注解:
let decimalDouble = 17.2e0 // 十進(jìn)制浮點(diǎn)數(shù)的17.2let hexadecimalDouble = 0x11.2p0 // 十六進(jìn)制浮點(diǎn)數(shù)的17.125
let paddedDouble = 000123.456let oneMillion = 1_000_000let justOverOneMillion = 1_000_000.000_000_1
Point 12.
數(shù)值型類型轉(zhuǎn)換
代碼事例:
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 現(xiàn)在是 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)")
作者:清風(fēng)撫柳 (DashGeng)
出處:http://www.companysz.com/dashgeng/
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注