I think a good use case for parameters inoutis the function swapTwoIntsprovided by Swift for programming .
func swapTwoInts(inout a: Int, inout b: Int) {
let temporaryA = a
a = b
b = temporaryA
}
Considering
var a = 0
var b = 1
you can easily call
swapTwoInt(&a, b: &b)
Scenario 2: no inout parameters
On the other hand, without parameters, the inoutfunction should be written as follows (more compactly)
func swapTwoInt(a: Int, b: Int) -> (a:Int, b:Int) {
return (a:b, b:a)
}
3 1:
let swapped = swapTwoInt(a, b: b)
a = swapped.a // was swapped.b, fixed as suggested by Martin R
b = swapped.b
, 2 . , , , .