无法在SWIFT中使用递归
-
21-12-2019 - |
题
我正在使用这个函数
func countFrom(from:Int, #to:Int) -> () {
println("\(from)")
if from < to {
countFrom(from + 1, to: to)
}
}
countFrom(1, to: 10)
}
.
但是编译我得到swift编译错误 -
命令/应用/ xcode6-beta2.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/swift失败了退出代码1
如果我删除了“计数(从+ 1,to:to)”,则没有更多错误。那是怎么了的?
解决方案
答:代码很好,编译器过时。每@ Matt的评论,这在Beta 4中有效。
控制台输出:
1
2
3
4
5
6
7
8
9
10
. 不隶属于 StackOverflow