Trailing Closure Syntax

suggest change

When the last parameter of a function is a closure

func loadData(id: String, completion: (String) -> Void) {
    completion("This is the result data")
}

The function can be called with trailing closure syntax. Swift 3 and later require the id label. Swift 2 omitted it, and a closure type could spell the parameter label as result.

loadData(id: "123") { result in
    print(result)
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents