swift语言之----元组
//元组是swift中特有的,OC中并没有相关类型
/*
它是一种数据结构,在数学中应用广泛
类似于数组或字典
可以定义一组数据
组成元组类型的数据称为"元素"
*/
//元组,数组,字典的区别
//1.使用数组来定义一组数据
let infoArray = ["wenjian",18,1.88]
//获取数组中的元素
let nameArray = infoArray[0]
//2.使用字典来定义一组数据
let infoDict = ["name":"wenjian","age":18,"height":1.88]
//获取字典中的元素
let nameDict = infoDict["name"]
//3.使用元组来定义一组数据
let infoTuple = ("wenjian",18,1.88)
//获取元组中的元素
let nameTuple = infoTuple.0
//4.使用元组定义一个网络请求的错误
//数组
let errorArray = ["Not Found",404]
//字典
let erroDict = ["erroMsg":"Not Found","erroCode":404]
//元组
let erroTuple = ("Not Found",404)
erroTuple.0
//给元组中所有的元素起别名
let erroTuple1 = (erroMsg:"Not Found",erroCode:404)
erroTuple1.erroMsg == erroTuple1.0
erroTuple1.erroCode == erroTuple1.1
//元组的别名就是元组的名称
let (erroMsg,erroCode) = ("Not Found",404)
erroMsg
erroCode