Swift元组的创建--使用

//元组把多个值组合成一个值 其中的值类型可以不同.

let HttpErrorCode = (404,"not found")

let (status,statusMe) = HttpErrorCode

//读取方式 0,1,2,3,4,下标.

print(HttpErrorCode.0)

print("The status code == \(status)")

print("The status mess == \(statusMe)")


let (abc,_) = HttpErrorCode

print(abc)


//元组的赋值

let http200err = (statuss:200,errcodes:"notfound")

print(http200err.statuss)

print(http200err.errcodes)

//元组在临时组织值得时候很有用,但是并不适合创建复杂的数据结构.若复杂的数据结构 使用类和结构体.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章