输入输出函数 inout parameters
func
swapTwoInts(inout a: Int, inout _ b: Int)
{
let
temporaryA = a a = b b = temporaryA }
var
someInt =
3
var
anotherInt =
107
swapTwoInts(&someInt, &anotherInt)
函数类型作为参数类型(Function Types as Parameter Types)
func printMathResult(
mathFunction
:
(Int, Int) ->
Int, _
a
: Int, _
b
: Int) {
print
(
"Result: \(mathFunction(a, b))"
) }
函数类型作为返回类型(Function Types as Return Types)
func stepForward(input: Int) -> Int
{
return
input +
1
}
func stepBackward(input: Int) -> Int
{
return
input -
1
}
func
chooseStepFunction(backwards: Bool) -> (Int) -> Int {
return
backwards ? stepBackward : stepForward }