【Functions】
1、不带返回值的函数:

2、通过tuple返回元素

返回的tuple可按如下方式使用:

3、External Parameter:

External parameter的使用:
4、Shorthand external parameter:

5、Default Parameter:

Default Parameter自动定义了external parameter:


6、Variadic Parameters,变长参数,在类型后面加上...:

7、Variable Parameter,函数参数默认是const,即函数body内无法改变参数值。要想在函数body内改变此值,需用var声明参数。

8、In-out参数:

使用in-out参数:

9、FunctionType:

可以在String Interpolation中调用函数:

10、FuntionType as Parameter Type:

11、FunctionType as Return Type:

【Closures】
1、三种Closure:

2、Closure Expression Syntax:


3、Inferring Type From Context

在单表达式Closure的情况下,return也可以省略:

4、Shorthand Argument Names,通过数字

5、Operator Function

6、Trailing Closure

array.map使用Trailing Closure的例子:

7、下述代码中,runningTotal会capture reference:

8、Closure are reference types。
浙公网安备 33010602011771号