swift - 无法快速使用递归

标签 swift ios8 swift-playground

我正在使用这个功能

    func countFrom(from:Int, #to:Int) -> () {
        println("\(from)")
        if from < to {
             countFrom(from + 1, to: to)
        }
    }
    countFrom(1, to: 10)
}

但是在编译时出现 Swift 编译器错误 -

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

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

最佳答案

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

控制台输出:

1
2
3
4
5
6
7
8
9
10

关于swift - 无法快速使用递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25015206/

相关文章:

c++ - 如何将 C++ 排序函数转换为 Swift?

ios - iOS8.4 和 Xcode 6.4 更新后,Xcode 应用安装失败

ios - 动态单元格高度尺寸不起作用

swift - 这段代码会导致 swift 崩溃怎么办?

ios - 提高 SceneKit Playground 速度

swift - 找不到接受提供的参数的 '/' 的重载

ios - 使用 Star Image 为 UIButton 设置边框

ios - SwiftUI 以异步方式加载很长的列表

Swift IAP 本地化价格

ios - UIView没有成员animateWithDuration?