-
-
Save jklausa/71d13ba944796a34a4f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestClass { | |
var aStruct: MyStruct; | |
init(inout initialStruct: MyStruct) { | |
aStruct = initialStruct; | |
} | |
func changeValueTo(newValue: Int) { | |
aStruct.aValue = newValue; | |
} | |
} | |
struct MyStruct { | |
var aValue: Int; | |
init(initialValue: Int) { | |
aValue = initialValue; | |
} | |
} | |
func changeValueTo(newValue: Int, inout inStruct: MyStruct) { | |
inStruct.aValue = newValue; | |
} | |
var aStruct = MyStruct(initialValue: 1234); | |
var aClass = TestClass(initialStruct: &aStruct); | |
println(aStruct.aValue); | |
aClass.changeValueTo(4321); // Nothing changed =/ | |
println(aStruct.aValue); // Still 4321 | |
changeValueTo(4321, &aStruct); | |
println(aStruct.aValue); // Its 4321 now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment