【发布时间】:2015-09-13 03:43:31
【问题描述】:
我对 swift 和闭包语法比较陌生
运行良好:
fileUpdater.run({ path in println("\(path)") })
但我无法让它工作:
fileUpdater.run({ (path: String) -> () in {
for file in self.changedFiles {
}
self.changedFiles.removeAll(keepCapacity: true)
println("mounted \(path)")
}})
因错误而失败
无法使用 ((String) -> ()) 类型的参数列表调用 run
这里是函数定义:
func run(function: (path: String) -> ()) { // more code
更新:以下内容现在通过了基本检查,但随后导致 LLVM 失败。
fileUpdater.run({ path in {
return println("mounted \(path)")
}})
多么可怕的错误信息:
Global is external, but doesn't have external or weak linkage!
i8* ()* @_TFFFC10SwiftTest211AppDelegate11updateFilesFS0_FT_T_U0_FSST_auL_4pathSS
invalid linkage type for function declaration
i8* ()* @_TFFFC10SwiftTest211AppDelegate11updateFilesFS0_FT_T_U0_FSST_auL_4pathSS
LLVM ERROR: Broken module found, compilation aborted
如果有帮助的话,我正在使用 Xcode 6.4(所以我认为是 Swift 1.x?)。
【问题讨论】:
-
将其定义为
func run(function: (String) -> ())有帮助吗?我无法重现这个。 -
不抱歉,没有帮助
-
你能告诉我们你的
run函数吗?