We know that in Swift2, the parameter of the method is a let value by default, which is immutable.
But we can add the var keyword before the parameter to change its invariance:
func foo(var i:Int){ i += 1 print(i)}
Unfortunately, in swift2.x+, it is clear that the Modifier keyword var for the method parameter will be removed in Swift3, so in order to produce this hateful warning, you must use the InOut keyword, and add the address character when you call the method to pass the argument:
i:Int){ i += 1 print(i)}i10foo(&i)print(i)
That's all!!!
However, in Xcode8.0beta Swift3.0 in the preview version, the situation has changed, run the above code, the compiler will prompt you inout the keyword misplaced, you have to put the inout behind the colon:
func test( i:inout Int){ i += 1 print(i)}var x = 10test(&x)print(x)
You can combine the one I wrote earlier on how to convert different types of mutable pointers in Swift, I believe you must have something to gain;]
Some changes of method variable parameter syntax in SWIFT3