ArraySlice in Array Swift [duplicate]
Asked Answered
U

1

36

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

Uranium answered 20/11, 2015 at 15:13 Comment(0)
A
92

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)
Arcanum answered 20/11, 2015 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.