Closures are self-contained blocks of functionality that can be passed around and used in
your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in
other programming languages.
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, hence the name “closures”. Swift handles all of the memory management of
capturing for you.
N O T E
Don’t worry if you are not familiar with the concept of “capturing”. It is explained in detail below in Capturing Values.
Global and nested functions, as introduced in Functions, are actually special cases of
closures. Closures take one of three forms:
Swift’s closure expressions have a clean, clear style, with optimizations that encourage
brief, clutter-free syntax in common scenarios. These optimizations include:
Closures are self-contained blocks of functionality that can be passed around and used in
your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in
other programming languages.
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, hence the name “closures”. Swift handles all of the memory management of
capturing for you.
N O T E
Don’t worry if you are not familiar with the concept of “capturing”. It is explained in detail below in Capturing Values.
Global and nested functions, as introduced in Functions, are actually special cases of
closures. Closures take one of three forms:
Swift’s closure expressions have a clean, clear style, with optimizations that encourage
brief, clutter-free syntax in common scenarios. These optimizations include:
การแปล กรุณารอสักครู่..
