As stated in other answers, as of Swift 3 placing var before a variable has been deprecated. Though not stated in other answers is the ability to declare an inout
parameter. Think: passing in a pointer.
func reduceToZero(_ x: inout Int) {
while (x != 0) {
x = x-1
}
}
var a = 3
reduceToZero(&a)
print(a) // will print '0'
This can be particularly useful in recursion.
Apple's inout
declaration guidelines can be found here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…