Created
September 24, 2014 14:18
-
-
Save anonymous/b697ad6af81b5d50239c to your computer and use it in GitHub Desktop.
This file contains 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