Skip to content

Instantly share code, notes, and snippets.

@VojtaStavik
Created May 8, 2019 13:14
Show Gist options
  • Save VojtaStavik/26e679f3bb370269a5020b0717d33da2 to your computer and use it in GitHub Desktop.
Save VojtaStavik/26e679f3bb370269a5020b0717d33da2 to your computer and use it in GitHub Desktop.
var vc1: UIViewController? = .init()
weak var weakVC1 = vc1
vc1 = nil
print(weakVC1 ?? "nil")
var vc2: UIViewController? = .init()
vc2?.loadViewIfNeeded() // Commenting this line out makes `weakVC2` nil, too.
weak var weakVC2 = vc2
vc2 = nil
print(weakVC2 ?? "nil")
@VojtaStavik
Copy link
Author

Console output is

nil
<UIViewController: 0x7f88cd816e00>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment