Junior — Middle
Milline märksõna kasutatakse muutuja väärtuse muutmiseks funktsiooni kehas?
sobes.tech AI
Vastus AI-lt
In Swift, to change the value of a variable passed to a function, the inout keyword is used. This allows passing the variable by reference so that changes within the function reflect on the original variable.
Example:
func increment(value: inout Int) {
value += 1
}
var number = 5
increment(value: &number)
print(number) // Will print 6
Note that when calling the function, the variable is passed with the & symbol.