本文介绍了Array Swift中的ArraySlice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数组上使用prefix方法后,我得到了称为arraySlice的东西.如何将其转换为数组?

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

我试图从FacebookGraphApi中获取Ints,然后要求输入前3个(前缀(3)),然后尝试将它们添加到新数组中.

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.

提前谢谢

推荐答案

只需使用切片初始化新的Array:

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)

这篇关于Array Swift中的ArraySlice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:33