The first day of Swift learning:
1: Use of arrays
Definition of the array:
Let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
2: Traversal of arrays
For num in numbers {
Print (num)
}
3: Also through subscript to make content
Let NUM1 = Numbers[0]
Let num2 = numbers[1]
4. Define variable non-volatile
' Let ' defines an immutable set of variables
' var ' defines a mutable array
5. Append content to a mutable array
Array1.append ("Wangwu")
6. When the array is initialized, if the value is assigned
If all content types are consistent during initialization, the content of that type is saved in the optional array
If all content types are inconsistent during initialization, the ' NSObject ' is saved in the optional array.
7. In Swift, the numbers can be added directly to the collection and no longer need to be converted to ' nsnumber '
8. In Swift, if you add a struct object to a collection, you still need to convert it to ' nsvalue '
Array2.append (Nsvalue (Cgpoint:cgpoint (X:10, y:10)))
9. No new values can be added before the array is instantiated
var array3: [String]
: Add value is not allowed before instantiation
Array3.append ("Laowang")
10. Must be an array of the same type to be able to merge
In development, the types of objects that are normally stored in arrays are the same!
11. Memory allocation
If you append an element to an array that exceeds the capacity, it is directly based on the existing capacity 2
Swift learns the first day of the array