Skip to content

Instantly share code, notes, and snippets.

@bjtitus
Created January 26, 2021 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjtitus/5140023db8fd42a8aeb96c67ad74a5fd to your computer and use it in GitHub Desktop.
Save bjtitus/5140023db8fd42a8aeb96c67ad74a5fd to your computer and use it in GitHub Desktop.
import Foundation
protocol Delegate: class {
}
@objc class Thing: NSObject {
weak var delegate: Delegate?
init(delegate: Delegate) {
self.delegate = delegate
}
func nothing() {
}
}
@objc
class MyClass: NSObject, Delegate {
lazy var thing: Thing = {
return Thing(delegate: self)
}()
deinit {
thing.nothing() // This crashes due to a cyclical reference to self.
}
}
func doThing() {
let thing = MyClass()
}
doThing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment