Definition of the array:
var Beijing line Line 10 = ["National Library", "BA Gou"]
Beijing Line Line 10. Count//or the length of the array
If Beijing line Line 10. IsEmpty {
println ("The array is empty");
}
Add a value to the array,
Beijing Line Line 10, append ("Agricultural exhibition Hall");
Beijing Line Line 10 + = ["Sun Palace", "Sanyuan Bridge", "Liang Qiao"]
Beijing Line Line 10 [0] = "Tuanjiehu"
Beijing Line Line 10. Insert ("Call Home", atindex:1)//Insert new value replace old value
To remove a value from an array
Beijing Line Line 10. Removeatindex (1)
Beijing Line Line 10. Removerlast ()//Remove Last
Iterating through an array
For station name in Beijing line Line 10 {
printf ("\ (station name)")
}
Sometimes we want to see the index value corresponding to each station name.
For (ordinal, station name) in enumerate (Beijing line Line 10) {
printf ("The Name of the" (ordinal) is: \ (station name) ")//String interpolation
}
Swift Notes 5