Preface
Swift provides two set types to store multiple values—array and dictionary. Everyone should know this. Before the New Year, I bought a Swift Advanced (swift 4.0). After the New Year, I am studying a little bit. I have to say that the things written by Miao Shen are pretty good. RMB 69 is nothing for programmers. If you are interested, you can buy one. It's really good.
When I learned arrays from scratch, I found that many functions are really useful. I won’t say much below. Let’s take a look at the detailed introduction together.
Variable array tips in Swift 4.0
We can use Xcode to create playgrounds for practice
Create an array first
let array = NSMutableArray(array: [1, 2, 3, 4 , 5, 6])
for in loop traversal
for x in array { print(x) }
1 2 3 4 5 6
Do you want to deduct the remaining elements of the first element for iterative traversal?
for x in (){ print(x) }
2 3 4 5 6
The dropFirst() function parameter is a value that can be added for x in (3) Print: 4 5 6.
Where there is first, there is basically last
Want to deduct elements other than the last 3 elements for traversal?
for x in (3){ print(x) }
1 2 3
Traversal with subscript and array element
for (num, element) in () { print(num, element) }
Print Left subscript Right element
0 1
1 2
2 3
3 4
4 5
5 6
Left subscript Right element
Summarize
The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.