//1. Sometimes it is necessary to split the data in the tuple for example:
var stu = (" Fan Bingbing ", "the female ")
//1) will be Stu assigns three variables to the data in the
var (name,age,gender) = Stu
//2) only partial variables are required , can be used . syntax assignment, or use an underscore to replace the blank position, as follows
var stu1 = (" Zhao Wei ","Max"," male " )
var (Name1,age1,_) = STU1
println (name)
// with Let You can only assign a value once when booting. equals constant
var (name,age,gender) = Stu
//
println (name)
// will be name when assigning other data, the data in the tuple does not change
name = " Li Chen "
2. Arrays
// An array is a data structure that stores data of the same data type in a certain order, using a name and subscript for reference.
//c language. int array[10]; Swift, using let to write several elements of length is a few, can only be assigned one time. Variable length with var guide .
// once the value is assigned length, the contents of the array cannot be changed
Let array:[Int]
Array = [1,2,3,4,5]
ARRAY[2] = 23
Array = [1,2,3,4,5]
// traversal of an array
Print (" first array:")
for (var i:Int =0; i<=4; i++)
{
Print(array[i])
}
println ()
// elements, variable-length arrays
var array1:[Int] = [1,2,3, 4,5]
array1 [0] = 2
Print (" second array:")
for (var i:Int =0; i<=4; i++)
{
Print(array1[i])
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
swift-08-tuple decomposition and array