Swift tuple _08_swift Primitive use

Source: Internet
Author: User

//: 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.