Swift set cut scores

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:

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 SubSequence type,It provides an array of sub-sequences:

Obviously,There is provided a front or from the start of the specified number of array split,In fact, there are many more methods of resolution here I will not go into details,You can go to look at the specific declaration in Xcode。

But it is worth mentioning that,Split out of sequence,Remains the original array index value - of course,Array is a value type,So the operation of the sub-sequence does not affect the original array:

Here we take two values ​​from the forward post,Visible sequence subscript index is still before the array fixedArray Continuation of,I put the word sequence to declare variables,You can modify the,The original array value remains unchanged。

This time if you want to use sequences that direct use of the,It has exactly the same with the array method。




It can not be used as an array,It also did not return an array of methods!

To re-assigned to an array type variable,Then you must use an array initializers to initialize it:

Then,Finally, we show you how to quickly remove one from the first three values ​​in an array as a new array:

Yes,Just a word。

Further reading

Slice(An array of segmented operation)

Security snoop array index of the array of slices Swift

Original article written by Gerber drop-off:R0uter's Blog » Swift set cut scores

Reproduced Please keep the source and description link:https://www.logcg.com/archives/1936.html

About the Author


The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *