Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArraySlice in Array Swift [duplicate]

after using the prefix method on an Array I get what is called an arraySlice. How can I transform this into an Array?

I am trying to fetch Ints from FacebookGraphApi then asking for the first 3 (prefix(3)) and trying to add them into a new array.

Thank you in advance

like image 848
JVS Avatar asked Nov 20 '15 15:11

JVS


People also ask

What is ArraySlice in Swift?

The ArraySlice type makes it fast and efficient for you to perform operations on sections of a larger array. Instead of copying over the elements of a slice to new storage, an ArraySlice instance presents a view onto the storage of a larger array.

What is .first in Swift?

first(where:) Returns the first element of the sequence that satisfies the given predicate.


1 Answers

Just initialize a new Array with the slice:

let arr1 = [0,1,2,3,4,5,6,7] let slice = arr1[2...5] let arr2 = Array(slice) 
like image 78
Code Different Avatar answered Sep 20 '22 12:09

Code Different