In addition to the accepted answer -
In Swift, functions are first class objects, that means that they can be passed as parameters.
In your examples, when there is a function that takes another function as an argument, you can either write the argument inline, using trailing closure syntax:
let id: Int = 1
retrieveData(id: id) {
self.update(with: $0)
}
But look at the function update(with:)
it is a function that takes a Record
and returns Void.
Another way to write this, rather than calling the function in the closure, is to just pass the function:
let id: Int = 1
retrieveData(id: id, completion: update)
Notice that you don't pass it a parameter, or oven brackets. When you pass a function this way, you are passing the function itself, not the result of evaluating the function.
I think this is even cleaner at the call site.