// // main.swift // tuple元组Demo // // Created by 程磊 on 15/5/20. // Copyright (c) 2015年 chenglei. All rights reserved. // import Foundation //元组的使用 //元组创建的第1种方式 let (x,y) = (1,2); //定义一个简单的元组 println("x is \(x) and y is \(y)"); //元组创建的第2种方式 let http404Error = (404,"Not Found"); println("http404Error = \(http404Error)"); //访问元组的值1 let (statusCode,statusMessage) = http404Error;//采用类似Dictionary的方式通过key来查询value println("statusCode = \(statusCode) and statusMessage = \(statusMessage)"); //访问元组的值2 let (justTheStatusCode,_) = http404Error;//如果仅需要获取元组中个别的值,可是使用"_"的方式来忽略不需要的值 println("justTheStatusCode = \(justTheStatusCode)"); //访问元组的值3 println("statusCode = \(http404Error.0) and statusMessage = " + String(http404Error.1));//使用序号来访问 //元组创建的第3种方法 let http200Status = (statusCode: 200,desc:"OK"); println("statusCode = \(http200Status.statusCode) and Desc is \(http200Status.desc)");原文链接:https://www.f2er.com/swift/327106.html