Last active
October 30, 2020 15:25
-
-
Save jsoneaday/77700365c33603ddf57599087ce51eb2 to your computer and use it in GitHub Desktop.
Using unowned for two objects that references each other
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 Unicycle { | |
var wheel: Wheel? | |
init() { | |
self.wheel = Wheel(parent: self) | |
} | |
deinit { | |
print ("Unicycle is being deinitialized") | |
} | |
} | |
class Wheel { | |
var parent: Unicycle? | |
init(parent: Unicycle) { | |
self.parent = parent | |
} | |
deinit { | |
print ("Wheel is being deinitialized") | |
} | |
} | |
var cycle: Unicycle? = Unicycle() | |
cycle = nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment