猿问

Swift中数组如何像OC中一样取subarrayWithRange

Swift中数组如何像OC中一样取subarrayWithRange获得子数组呢?

慕田峪4524236
浏览 2889回答 2
2回答

狐的传说

上面获得的是ArraySlice 需要再用Array来包一层let a = [1,2,3,4,5,6]let b = a[0...1]//b is type of ArraySlicelet b= Array(a[0...1])//b is array 

慕勒3428872

let a = [1,2,3,4,5,6]let b = a[2...5]//b = [3,4,5,6]
随时随地看视频慕课网APP
我要回答