When I try the following code:雨燕3.1的错误:无法调用“步幅”型
extension Int{
func hello(to end: Int, by step: Int, task: (Int) -> Void){
for i in stride(from: 4, to: 8, by: 2) {
task(i)
}
}
}
And I get the error saying:
error: cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)' for i in stride(from: 4, to: 8, by: 2)
note: overloads for 'stride' exist with these partially matching parameter lists: (to: Self, by: Self.Stride), (through: Self, by: Self.Stride) for i in stride(from: 4, to: 8, by: 2)
的参数列表,我不为什么这种类型的错误发生
我不能说为什么会出现此特定错误,但它工作正常,如果它不是在'Int'扩展。 – vadian
比较https://stackoverflow.com/q/39602298/2976878。在你的具体情况中,问题在于编译器看到了被声明为实例成员而不是全局函数(但现在不可用)的Swift 2'stride'方法。解决方案是相同的,用模块名称前缀呼叫以消除歧义。 – Hamish