1) Arrays in Swfit can only hold values of the same type, unlike OC and Java
2) Swift initialization method
var s0 = [1,2,3,4,5]
var s1: [Int] = [1 ,2 ,3 ,4 ,5]
var s2: [String]
var s3 = [Int] ()
In Swift if the copy operation S3 = S1, S3 copies a copy of the S1 value, which is a deep copy. Two-part values do not affect each other.
the value of s3[0] has changed, but the value of S1 has not changed. The output is 1, 2, 3, 4, 5.
Note: In this case, var s = [], at this time is not an array, cannot make s [1] = 3 The specific reason is not clear now!
3) IsEmpty (OC not) determines whether the count of array is 0
The above S2 is now unable to invoke the method because it is just a declaration that there is no real memory mismatch.
4) + = (OC array not) adds one or more values at the end, and adds one when it is equivalent to append. Multiple hours is equivalent to adding an array between them.
However, adding a value when writing the code will cause an error.
5) S1 [StartIndex ... endIndex] value = [StartIndex EndIndex]
6) How the array is traversed
- For ... in this is very common.
- Use tuples to return subscripts with specific values for (index, value) in enumerate in (array)
for (Index, value) inch Enumerate (S1) {
println ("s1[\ (index)] =\ (value)")
}
7) New creation mode [type] (Count:repeatedvalue)
var s6 = [String] (count:3 repeatedvalue: "Hello,world" )
New methods for arrays in swif compared to arrays in OC