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 MyClass { | |
var value: Int | |
init(value v: Int) { value = v } | |
} | |
var instanceOfMyClass = MyClass(value: 42) | |
var assignedInstance2 = instanceOfMyClass | |
assignedInstance2.value = 2 // Change the copied instance | |
instanceOfMyClass.value // 2: Original is also changed |
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
struct MyStruct { | |
var value: Int = 0 | |
} | |
var instanceOfMyStruct = MyStruct(value: 42) | |
var assignedInstance1 = instanceOfMyStruct | |
assignedInstance1.value = 2 // Change the copied instance | |
instanceOfMyStruct.value // 42: Original is unchanged |
NewerOlder