在swift的官方文档中,关于结构体closure给出这样一段描述:
Functions are actually a special case of closures: blocks of code that can be called later. The code in a closure has access to things like variables and functions that were available in the scope where the closure was created, even if the closure is in a different scope when it is executed—you saw an example of this already with nested functions. You can write a closure without a name by surrounding code with braces ({}). Use in to separate the arguments and return type from the body.
翻译整理一下:
1.函数其实是一种特殊的机构体:一段可以在之后相应的代码块。
2.结构体创建的时候参数可以是值或者函数,甚至是另一个结构体。
3.给出了结构体的创建方法,既用大括号{}覆盖,然后用in关键字将参数和返回值分开。
下面是官方文档给出的例子: