I know what inout
does for value types.
With objects or any other reference type, is there a purpose for that keyword in that case, instead of using var
?
Code example:
private class MyClass {
private var testInt = 1
}
private func testParameterObject(var testClass: MyClass) {
testClass.testInt++
}
private var testClass: MyClass = MyClass()
testParameterObject(testClass)
testClass.testInt // output ~> 2
private func testInoutParameterObject(inout testClass: MyClass) {
testClass.testInt++
}
testClass.testInt = 1
testInoutParameterObject(&testClass) // what happens here?
testClass.testInt // output ~> 2
It could be the same as simply the var
keyword in the parameter list.
var
parameter to a new object does simply nothing. I just oversaw that. It is the same for all reference types then? – Theatrical