Swift Learning-tuple type

Source: Internet
Author: User

Knowledge Points:

    1. the element in the tuple data can have a name or it can have no name
    2. elements in the tuple data can be empty
    3. element Access can be by element name or subscript
    4. elements in tuple data declared as Var can be changed
    5. You can specify the type of the element (the name of the element cannot be added in cases where the element type is explicitly indicated)
    6. you can receive tuple data with multiple variables
    7. elements can be assigned to multiple variables individually
    8. you can omit the value of an element with an underscore to remove other elements
Example code:

: Playground-noun:a place where people can playimport uikit//tuple type consists of n any type of data (n >= 0)//The data that makes up the tuple type can be called "element"//1, with element The name and the declaration without the element name let position = (x:10.5, y:20)//position has 2 elements, X, Y is the name of the element let Position2 = (20, 40)//declaration of no element name let person = (Name: "Jack")//person has only one element and the type of the element does not require let data = ()//NULL tuple//2, element access//with element name access position.xposition.y//with element subscript access posit Ion.0position.1//positon is a constant so cannot change the value of the element//2, change the value of the element var Mulpos = (a:10, b:20) MULPOS.A = 20mulpos.0//3, the output of the tuple println ( Mulpos)//4, the type of the specified element var Person2: (Int, String) = ("Jack")//person's No. 0 element can only be of type Int, the first element can only be a String type// Note: The element name cannot be added in cases where the element type is explicitly specified//Therefore, the following statement is wrong//var person: (Int, String) = (age:20, name: "Jack")//5, you can receive the tuple data var (x, y) with multiple variables  = (ten, +)//X is 10,y is 20var point = (x, y)//point consists of two elements, 10 and 20//6 respectively, can be assigned to multiple variables var point1 = (Ten, three) var (x1, y1) = point1//x is 10,y is 20//7, can use underscore _ ignore the value of an element, take out the value of other elements var person22 = ("Jack") Var (_, name) = person22//here only to receive Jack, ignoring 20

Swift Learning-tuple type

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.