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