我遇到了这个错误,我是 Swift 的新手。我想获取 >= 5 的数组的最后 5 个点,并将这 5 个点作为数组参数传递给函数。我怎样才能做到这一点并克服这个错误?
无法将“ArraySlice”类型的值转换为预期的参数类型“[CGPoint]”
if (self.points?.count >= 5) {
let lastFivePoints = self.points![(self.points!.count-5)..<self.points!.count]
let angle = VectorCalculator.angleWithArrayOfPoints(lastFivePoints)
}
最佳答案
你需要转换ArraySlice
至 Array
使用方法Array(Slice<Type>)
if (self.points?.count >= 5) {
let lastFivePoints = Array(self.points![(self.points!.count-5)..<self.points!.count])
let angle = VectorCalculator.angleWithArrayOfPoints(lastFivePoints)
}
关于arrays - swift 错误 : Cannot convert value of type 'ArraySlice' to expected argument type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35028784/