import UIKit
var point = (5,2) //元祖类型为Int类型
var httpResponse = (404,"Not Found") //元祖类型为Int和String
var point2 :(Int, Int, Int) = ( 5 , 5 , 2)
var httpResponse2 :(Int,String) = (200, "OK")
let (statusCode , statusMessage) = httpResponse2
print(statusCode)
print(statusMessage)
//命名元组分量的隐式写法
let point3 = (x:1,y:2)
point3.x
point3.y
//命名元组分量的显示写法
let point4:(x:Int,y:Int) = (222,444)
point4.x
point4.y
//元祖解包写法 用下划线代表忽略这个值
let loginResponse = (true,"loginName")
let (isLogin,) = loginResponse
if isLogin{
print("登陆成功")
}else{
print("登陆失败")
}
//使用print打印字符串差值
let a = 2
let b = 3
print("(a) * (b) = (a*b)")
网友评论