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)

//元組在臨時組織值得時候很有用,但是並不適合創建複雜的數據結構.若複雜的數據結構 使用類和結構體.

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