I feel a bit lost using swift inout parameter in the following code:
var shouldContinue: Bool = true
func doSomeWork1(shouldContinue: inout Bool)
{
while shouldContinue
{
// ERROR: the compiler wants: doSomeWork2(shouldContinue: &shouldContinue)
doSomeWork2(shouldContinue: shouldContinue)
}
}
func doSomeWork2(shouldContinue: inout Bool)
{
while shouldContinue
{
}
}
Why does the compiler want doSomeWork2(shouldContinue: &shouldContinue)
instead of the compiler wants: doSomeWork2(shouldContinue: shouldContinue)
? isn't shouldContinue
already a pointer in the scope of doSomeWork1() ???
shouldContinue
it won't change inside the functions, but the old value will be restored when returning from the functions ? – Fylfot