gpt4 book ai didi

swift - 如何通过参数将变量传递给 stride

转载 作者:行者123 更新时间:2023-11-28 12:22:19 27 4
gpt4 key购买 nike

我试图通过参数将一个 Int 常量传递给我的 for 循环的 stride。它采用类型 T.stride。

let notchStep:Int = 5

for degrees:Double in stride(from: 0, to: 359, by: notchStep) {

我收到这个错误:

无法使用类型为“(from: Int, to: Int, by: Int)”的参数列表调用“stride”。我可以传递什么类型的值或如何将我的 Int 转换为合适的类型?

最佳答案

尝试删除代码中的 :Double,这样它会显示:

let notchStep: Int = 5

for degrees in stride(from: 0, to: 359, by: notchStep) {
// do something
}

查看方法签名,我认为混合 IntsDoubles 会产生问题。

关于swift - 如何通过参数将变量传递给 stride,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44448858/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com