元祖的定义
let (x, y) = (1, 2) //定义一个简单的元组
println("x is \(x) and y is \(y)") //是这么输出元祖的x值和y值的
元祖的访问
// 同时访问元祖的x值和y值
let http404Error = (404, "Not Found") //定义一个由Int和String组成的元组
let (statusCode, statusMessage) = http404Error //采用类似Dictionary的方式, 通过key去拿到值
println("statusCode is \(statusCode) and statusMessage is \(statusMessage)")
//如果仅需要元组中x值或y值, 可以使用"_"的方式来忽略不需要的值
let (justTheStatusCode, _) = http404Error
println("justTheStatusCode is \(justTheStatusCode)")
//访问元组的值, 使用序号
println("status code is \(http404Error.0)") // x值
println("message is \(http404Error.1)") // y值
元祖的创建
let http200Status = (statusCode: 200, desc: "OK")
println("The status code is \(http200Status.statusCode)")
println("The status msg is \(http200Status.desc)")