let http404Error = (404, "Not Found")// http404Error 的类型是 (Int, String),值是 (404, "Not Found")// 可以在声明时指定其中元素的名字let(statusCode, statusMessage)= http404Errorprint("The status code is \(statusCode)")// 输出“The status code is 404”print("The status message is \(statusMessage)")// 输出“The status message is Not Found”// 你可以在定义元组的时候给单个元素命名:let http200Status = (statusCode:200, description:"OK")
let age =-3assert(age >=0, "A person's age cannot be less than zero")// 因为 age < 0,所以断言会触发if age >10 {print("You can ride the roller-coaster or the ferris wheel.")} elseif age >0 {print("You can ride the ferris wheel.")} else {// 代码已经检查了条件,直接触发断言失败assertionFailure("A person's age can't be less than zero.")}