What is the correct way to write multiple trailing closures in Swift?

2.5k Views Asked by At

I keep getting an error from swift playgrounds that it can't find the "missing argument for parameter 'closure' in call."

func someFunc(closure: () -> (), closure2: () -> ()) {
    closure()
    closure2()
}

someFunc() {
    print("Calling from closure()")
} closure2: {
    print("Calling from closure2()")
}
1

There are 1 best solutions below

0
On BEST ANSWER

Multiple trailing closures are a new Swift 5.3 beta feature. Your code compiles and runs correctly in Xcode 12 beta using Swift 5.3 beta, as shown in this screen shot:

enter image description here

It is probable that the environment in which you are running does not have a Swift 5.3 beta compiler.