0

Variable Parameters

Is it possible in swift 4.1 to Use the keyword var as a prefix to the parameter name to define a variable parameter? ex. func myFunc(var num1: Int, num2: Int) -> Int { num1 = num1 + num2 return num1 }

24th May 2018, 6:24 PM
Smit Mehta
Smit Mehta - avatar
1 Resposta
0
Argument of a function in Swift is let by default so change it to var if you need to alter the value i.e, func reduceToZero(var x:Int) -> Int { while (x != 0) { x = x-1 } return x }
4th Jun 2018, 9:04 AM
Dipak