The array in Swift is denoted by []
1. Create an empty array
Let Emptyarr = [String] ()
Let emptyArr1: [NSNumber] = []
Both of these methods can be
2. Accessing elements
var numarr=["1", "2", "3"]
println ("first element: \ (Test1array[0])")
println ("last element: \ (test1array.last)")
3. Determine if the array is empty
Emptyarr.count ==0 or Emptyarr.isempty
4. Modifying an array
var strarr = ["A", "B", "C", "D", "E", "F", "G"]
strarr[1]= "X"
strarr[2...5]=["C", "D", "E", "F"]
Print (Strarr)
5. Array loops
for (INDEX,STR) in Strarr.enumerate () {
Print ("\ (index): \ (str)")
}
6. Array insertion
1 adding elements at the end
Strarr.append ("O")
2 Insert to specified position
Strarr.insert ("Y", atindex:1)
Print (Strarr)
7. Array Delete element
1 Delete the element at the specified position
Strarr.removeatindex (1)
2 Delete last Element
Strarr.removelast ()
Print (Strarr)
Note: Swift requires an array to be able to use two points correctly
1, the array must be initialized
2, you must specify the data type, you can assign a value to the compiler to automatically recognize the data type, or you can specify it yourself.
Swift Learning notes-arrays