Skip to content

Instantly share code, notes, and snippets.

@jsoneaday
Last active October 30, 2020 15:25
Show Gist options
  • Save jsoneaday/77700365c33603ddf57599087ce51eb2 to your computer and use it in GitHub Desktop.
Save jsoneaday/77700365c33603ddf57599087ce51eb2 to your computer and use it in GitHub Desktop.
Using unowned for two objects that references each other
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