xcode - Swift 中递归引用自身的函数

标签 xcode recursion swift

递归函数目前会在使用 swift 的 xcode 项目中导致编译时错误,但在 Playground 中工作得很好。在 Xcode 6 beta 4 的发行说明中:

Nested functions that recursively reference themselves or other functions nested in the same outer function crash the compiler. (11266246) For example:

func foo() {
  func bar() { bar() }
  func zim() { zang() }
  func zang() { zim() }
}

Workaround: Move recursive functions to the outer type or module context

将递归函数移动到外部类型或模块上下文是什么意思?

最佳答案

这意味着您应该在另一个函数之外声明该函数:

func bar() { bar() }
func zim() { zang() }
func zang() { zim() }
func foo() {
}

关于xcode - Swift 中递归引用自身的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25110699/

相关文章:

c++ - 如果我必须组织编译源,这是不好的做法吗

Python - 整理代码 - 循环和递归特性

javascript - 从 JSON 数组 react TreeView

python -(家庭作业)需要有关我的网格递归函数的帮助

swift - 为什么 UITableViewCell 宽度小于 UITableView 宽度

swift - Xcode 的布局问题

ios - 来自 NSMutableURLRequest 的 CSV 解析丢失了前 150 行

swift - 当应用程序不是焦点时运行一个在后台倒计时的计时器? swift

arrays - 如何在 Swift 中比较 Equatable

ios - UIImageView 上 CALayer 子层的一致性居中