无法在swift中使用递归

无法在swift中使用递归,swift,ios8,swift-playground,Swift,Ios8,Swift Playground,我正在使用这个函数 func countFrom(from:Int, #to:Int) -> () { println("\(from)") if from < to { countFrom(from + 1, to: to) } } countFrom(1, to: 10) } func countFrom(from:Int,#to:Int)->(){ println(“\(from

我正在使用这个函数

    func countFrom(from:Int, #to:Int) -> () {
        println("\(from)")
        if from < to {
             countFrom(from + 1, to: to)
        }
    }
    countFrom(1, to: 10)
}
func countFrom(from:Int,#to:Int)->(){
println(“\(from)”)
如果从<到{
countFrom(从+1到:到)
}
}
countFrom(1,到:10)
}
但在编译时,我得到了Swift编译器错误-

命令/Applications/Xcode6-Beta2.app/Contents/Developer/Toolchains/xcodefault.xctoolchain/usr/bin/swift失败,退出代码为1


如果我删除了“countFrom(from+1,to:to)”,那么就不会再有错误了。有什么问题吗?

回答:代码很好,编译器已经过时了。根据@Matt的评论,这在Beta 4中运行良好

控制台输出:

1
2
3
4
5
6
7
8
9
10

它应该是赛尔夫的吗?这是Xcode 6 beta 4中的一个已知问题——递归的嵌套函数会使编译器崩溃。他们在发行说明中提到了这一点,并说解决方法是“将递归函数移到外部类型或模块上下文中。”“Command/Applications/Xcode6-Beta2.app/Contents/…”好吧,首先,我要升级到最新的beta版,然后再问太多关于奇怪行为的问题。