Created
January 26, 2021 05:26
-
-
Save bjtitus/5140023db8fd42a8aeb96c67ad74a5fd to your computer and use it in GitHub Desktop.
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
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