Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSwiftweak vs unowned mechanicsSingle-choice MCQ

Consider this code. The closure captures `self` weakly. At the moment `handler` is invoked after `self` has been released, what is the precise runtime mechanism that makes `self` evaluate to nil inside the guard?

final class Controller { var handler: (() -> Void)? func wire() { handler = { [weak self] in guard let self else { return } self.doWork() } } func doWork() {} }