The discussion of the removal of Var from a function parameter is fully documented within this submission on GitHub: Remove Var Parameters
In that document you will find that people often confuse var
parameters with inout
parameters. A var
parameter simply means that the parameter is mutable within the context of the function, while with an inout
parameter the value of the parameter at the point of return will be copied out of the function and into the caller's context.
The correct way to solve this problem is to remove var
from the parameter and introduce a local var
variable. At the top of the routine copy the parameter's value into that variable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…