Skip to content

Instantly share code, notes, and snippets.

@roz0n
Created February 22, 2021 06:13
Show Gist options
  • Save roz0n/82f12845d082c6b78399953816bf9b90 to your computer and use it in GitHub Desktop.
Save roz0n/82f12845d082c6b78399953816bf9b90 to your computer and use it in GitHub Desktop.
Presenting from detached view controllers in Swift
// UIViewController extension to get root VC
func getRootViewController(of nestedViewController: UIViewController) -> UIViewController? {
return nestedViewController.view.window?.rootViewController
}
// In use inside non-root VC
let vc = UINavigationController(rootViewController: CurrencySelectorViewController(type: type))
vc.modalPresentationStyle = .overFullScreen
if let root = getRootViewController(of: self) {
root.present(vc, animated: true, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment