Swift - 尾随闭包语法 [英] Swift - Trailing Closure Syntax
本文介绍了Swift - 尾随闭包语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在深入研究 Apple 的 Swift lang,但在使用尾随闭包语法时遇到了一些问题,例如:
I'm diving into Swift lang by Apple and have some problems using the trailing closure syntax, example:
func test(txt: String, resolve: (name: String) -> Void) {
resolve(name: "Dodo")
}
// Errors here complaining on resolve param
test("hello", (name: String) {
println("callback")
})
如何解决?
推荐答案
你的闭包语法错误
test("hello", {(name: String) in
println("callback")
})
或
test("hello", {
println("callback: \($0)")
})
或
test("hello") {(name: String) in
println("callback")
}
或
test("hello") {
println("callback: \($0)")
}
这篇关于Swift - 尾随闭包语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文