Swift Language-tuples

Source: Internet
Author: User

1. The concept of tuple 1-tuple

A tuple is a composite data type. Using parentheses to contain a set of data, you can group different types of data together. You can use implicit type inference, or you can have type callouts.
Examples are as follows:

#import Foundationvar teacher:("Miss Yang",26,1.59//隐氏类型推断var teacher1:(String,age,height)=("Miss zhang",30,1.65)
Access to 2-tuple data

1. Use subscript access, which is similar to getting an array element. The subscript is also starting from 0.
Examples are as follows:

#import Foundationvar teacher:("Miss Wong",31,1.65//隐氏类型推断println(teacher.0)println(teacher.2)

2. Give each data a variable. Corresponds with a set of variable groups and tuple values.
Examples are as follows:

#import Foundationvar teacher:(name,age,height)=("Miss Lee",50,1.71//隐氏类型推断println(name)println(age)println(height)

3. Use key-value pairs. Let the key-value parameter be inside the parentheses of the tuple. Use points to access.

#import Foundationvar teacher=(name:"Miss Song",age:18,height:1.53//隐氏类型推断println(teacher.name)println(teacher.age)println(teacher.height)

Swift Language-tuples

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.