๐Ÿ”ฐclosure

Swift โŸฉ type โŸฉ basic types โŸฉ closure

Closures are functions that run in place, without the need for a name. Closures can capture and store references to any constants and variables from the context in which they are defined. This is known as closing over those constants and variables.

scene.setOnStartHandler {
    // โญ๏ธ body of the closure
}

The parameters in closure expression canโ€™t have a default value.

Closures take one of three forms:

  • Global functions๏ผš have a name and donโ€™t capture any values.

  • Nested functions๏ผš have a name and can capture values from their enclosing function.

  • closure expression๏ผš unnamed, can capture values from their surrounding context.

๐Ÿ‘‰ see๏ผšClosures

Last updated