changjiashuai's blog

Runnig...

The future belongs to those who believe in the beauty of their dreams.


Swift基础---Tuples

声明

let http404Error = (404, "Not Found")
// http404Error is of type (Int, String),
// and equals (404, "Not Found")

使用

let (statusCode, statusMessage) = http404Error
println("The status code is \(statusCode)")
// prints "The status code is 404"

println("The status message is \(statusMessage)")
// prints "The status message is Not Found"

忽略不用的值

let (justTheStatusCode, _) = http404Error
println("The status code is \(justTheStatusCode)")
// prints "The status code is 404"

通过索引访问

println("The status code is \(http404Error.0)")
// prints "The status code is 404"

println("The status message is \(http404Error.1)")
// prints "The status message is Not Found"

指定Tuples的名字

let http200Status = (statusCode: 200, description: "OK")

println("The status code is \(http200Status.statusCode)")
// prints "The status code is 200"

println("The status message is \(http200Status.description)")
// prints "The status message is OK"
最近的文章

Swift基础---类型别名

如何定义typealias AudioSample = UInt16var maxAmplitudeFound = AudioSample.min //0…

继续阅读
更早的文章

Swift基础---Optionals

描述 There is a value, and it equals x There isn’t a value at alllet possibleNumber = "123"let convertedNumber = possibleNumber.toInt()// convertedNumber is inferred to be of type// "Int?", or "optional Int" !表示确定有值 ?可能有值if convertedNumber { p...…

继续阅读