Retrieving a fixed amount of data from a Swift Array

前端 未结 2 1072
情歌与酒
情歌与酒 2021-01-22 22:33

I have var toPlotLines:[Int] = [200, 300, 400, 500, 600, 322, 435] and I want to retrieve the first four integers from the array. Can I do

2条回答
  •  醉梦人生
    2021-01-22 23:00

    The error message is misleading. The problem is that toPlotLines[0 ..< n] is not an Array but an ArraySlice:

    The Array-like type that represents a sub-sequence of any Array, ContiguousArray, or other ArraySlice.

    To create a "real array", use

    graphView.graphPoints = Array(toPlotLines[0 ..< n])
    

提交回复
热议问题