inout parameter in a function can be changed in the function and the value kept on return.
The same for closure.
Here is Swift language statement: https://docs.swift.org/swift-book/LanguageGuide/Functions.html
Function parameters are constants by default. Trying to change the value of a function parameter from within the body of that function results in a compile-time error. This means that you can’t change the value of a parameter by mistake. If you want a function to modify a parameter’s value, and you want those changes to persist after the function call has ended, define that parameter as an in-out parameter instead.
You write an in-out parameter by placing the
inout
keyword right before a parameter’s type. An in-out parameter has a value that is passed
in to the function, is modified by the function, and is passed back
out of the function to replace the original value. For a detailed discussion of the behavior of in-out parameters and associated compiler optimizations, see
In-Out Parameters.
You can only pass a variable as the argument for an in-out parameter. You cannot pass a constant or a literal value as the argument, because constants and literals cannot be modified. You place an ampersand (
&
) directly before a variable’s name when you pass it as an argument to an in-out parameter, to indicate that it can be modified by the function.