-3

I'm not sure how

let logMessage = SKAction.run() {
  print("Reached bottom!")
}

works when the documentation of the declaration of run is

class func run(_ block: @escaping () -> Void) -> SKAction

How is it that the block is defined after the parentheses and still picked up by run()? I'm a total beginner to Swift, and I couldn't find anything explaining an instance where an argument is defined after the parentheses.

WestaAlger
  • 501
  • 3
  • 12

1 Answers1

1

This is called trailing closure syntax:

A trailing closure is written after the function call’s parentheses, even though it is still an argument to the function. When you use the trailing closure syntax, you don’t write the argument label for the closure as part of the function call.

If, as in your example, the function has no other arguments, you can even omit the parentheses in run().

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256