in most cases,If we want to get the contents of a section of the array (for example, front-to-middle,Some of the values of the array or the last),This time you need to traverse the array to assign a new array:
1 2 3 4 5 6 7 |
let fixedArray = [1,2,3,4,5,6] var myArray:[Int] = [] for (i,n) in fixedArray.enumerate() { if i > 3 {break} myArray.append(n) } |
Such an array of short, better said it does not matter,However, if the array is relatively large and we need to value and more,It is clear that it is a waste of time to traverse up。
Swift in itself provides an array of features split,This mechanism is called [crayon-679bca[……]