Search code examples
arraysswift

ArraySlice to Array in Swift


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


Solution

  • 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)