Swift 关闭错误
Swift Closure Error
我对 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)")
}})
因错误而失败
Cannot invoke run with an argument list of type ((String) -> ())
函数定义如下:
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?),如果有帮助的话。
移除块体周围多余的花括号。它们既不需要也不允许。
这是错误的:
fileUpdater.run({ path in { < curly brace not allowed
println("mounted \(path)")
}})
^
curly brace not allowed
这是正确的:
fileUpdater.run({ path in
println("mounted \(path)")
})
我对 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)")
}})
因错误而失败
Cannot invoke run with an argument list of type ((String) -> ())
函数定义如下:
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?),如果有帮助的话。
移除块体周围多余的花括号。它们既不需要也不允许。
这是错误的:
fileUpdater.run({ path in { < curly brace not allowed
println("mounted \(path)")
}})
^
curly brace not allowed
这是正确的:
fileUpdater.run({ path in
println("mounted \(path)")
})