What does the expression () -> () = {} mean in Swift?
1 answer
The argument completion
is of type () -> ()
. This is a closure that has no parameters and has a void return type.
= {}
is the default value for the parameter, meaning you really don't need to skip the closure if you don't need it.
Thus, you can call it like:
foo(withCompletion: {
// your code here
})
or (using the closing closure syntax):
foo() {
// your code here
}
or (if you don't want to use completion closure):
foo()
+7
source to share