: Playground-noun:a place where people can playimport uikit//Swift by default, the parameters passed in are not modifiable, that is, the let type, which is the constant parameter//if you want to modify the parameter Value, you need to add "var" to the parameter, that is, the variable parameter, func tobinary (Var num:int), String//Converts a number to binary {var result = "" while num! = 0 { result = String (num%2) + result num/= 2} return result}var number = 69toBinary (number) Number/ /input result or 69, explain the function of the variable parameter modification, does not affect the external variable itself//the following two function also proves that the variable parameter does not affect the external variable itself (including arrays and dictionaries) var a = 1func testchangeintfunction (var a:int {a = 0}testchangeintfunction (a) Avar arr = [2, 3]func Testchangeintfunction (var a:[int]) {a = [3, 4]}testchangeintf Unction (arr) arr/*--------------------------------------------------------------------*///So how do you change the external variable itself within a function? Here is the use of another keyword "inout"//This can be understood as a pointer to the parameter (that is, memory address) func Changeeachother (inout a:int, inout b:int) {Let temp = a A = b b = Temp}var x = 0, y = 100print ("x = \ (x), y = \ (y)") Changeeachother (&x, B: &y) print ("x = \ (x), y = \ (y)")// Swift's own swap function//swap (&< #T # #a:t# #T #>, &< #T # #b: t# #T #>)
SWIFT-31-constant parameters, variable arguments, and inout parameters