Reputation: 21304
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")
})
How to fix it?
Upvotes: 14
Views: 11962
Reputation: 11868
you have the wrong closure syntax
test("hello", {(name: String) in
println("callback")
})
or
test("hello", {
println("callback: \($0)")
})
or
test("hello") {(name: String) in
println("callback")
}
or
test("hello") {
println("callback: \($0)")
}
Upvotes: 27