//: Playground-noun:a Place where people can playImport UIKit//1. Definition of a tuple//describes the status of network Connections 200-ok 404-notfound 304-redirection//(1) Definition of tuple variablesvarHttperror = (404,"NotFound") print (httperror)//(2) omit the tuple variable name, but directly specify the name of each field in the tuplevar(code, MSG) = (304,"redirection") print (code) print (msg)//(3) explicitly specifying a type type annotation for a tuplevarHttpok: (code:int, msg:string) = ( $,"OK")//(4) the easiest wayvarhttpOK2 = (Code: $, msg:"OK") print (httpok2.code) print (httpok2.msg)//2. Accessing members in tuples (fields)//(1) Access directly by field name//(2) Access members by serial numberPrint (httpOK2.0) print (httpOK2.1)varErrocode = httpOK2.0varErromsg = httpOK2.1//(3) Partial value, other fields are not concernedLet (Errcode, _) =httpok2print (Errcode)//3. Tuples are generally used in functions, and tuples are used when the function requires multiple return values
Swift tuple _08_swift Primitive use