-
-
Save rintaro/1668e46bc969c5f991079dd5bf530dd1 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
protocol Resettable { | |
mutating func reset() | |
init() | |
} | |
extension Resettable { | |
mutating func reset() { | |
self = Self() // Assigning to 'self'. | |
} | |
} | |
class Foo : Resettable { | |
var value: Int | |
required init() { | |
value = 0 | |
} | |
} | |
var ref1 = Foo() | |
let ref2 = ref1 | |
assert(ObjectIdentifier(ref1) == ObjectIdentifier(ref2)) | |
ref1.value = 42 | |
assert(ObjectIdentifier(ref1) == ObjectIdentifier(ref2)) | |
ref1.reset() | |
assert(ObjectIdentifier(ref1) != ObjectIdentifier(ref2)) | |
assert(ref1.value == 0) | |
assert(ref2.value == 42) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment