Skip to content

Instantly share code, notes, and snippets.

@jklausa
Forked from anonymous/Reference problem
Created September 24, 2014 14:19
Show Gist options
  • Save jklausa/71d13ba944796a34a4f1 to your computer and use it in GitHub Desktop.
Save jklausa/71d13ba944796a34a4f1 to your computer and use it in GitHub Desktop.
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