Swift错误:无法将"ArraySlice"类型的值转换为预期的参数类型 [英] Swift Error: Cannot convert value of type 'ArraySlice' to expected argument type

查看:614
本文介绍了Swift错误:无法将"ArraySlice"类型的值转换为预期的参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到此错误,并且是Swift的新手.我想获取> = 5的数组的最后5个点,并将这5个点作为数组参数传递给函数.我该如何实现并克服此错误?

I'm getting this error and am new to Swift. I want to take the last 5 points of an array >= 5, and pass those 5 points as an array argument to a function. How can I achieve this and get past this error?

无法将类型为"ArraySlice"的值转换为预期的参数类型为"[CGPoint]"

Cannot convert value of type 'ArraySlice' to expected argument type '[CGPoint]'

if (self.points?.count >= 5) {
    let lastFivePoints = self.points![(self.points!.count-5)..<self.points!.count]
    let angle = VectorCalculator.angleWithArrayOfPoints(lastFivePoints)
}

推荐答案

您需要使用方法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)
}

这篇关于Swift错误:无法将"ArraySlice"类型的值转换为预期的参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆