Skip to content

Instantly share code, notes, and snippets.

@rsaenzi
Last active June 12, 2019 17:50
Show Gist options
  • Select an option

  • Save rsaenzi/d352a676affc84c9c191f5feb0b9e384 to your computer and use it in GitHub Desktop.

Select an option

Save rsaenzi/d352a676affc84c9c191f5feb0b9e384 to your computer and use it in GitHub Desktop.
Small function to get the App Delegate of any iOS app
//
// AppDelegate.swift
//
// Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/)
// Copyright © 2019. All rights reserved.
//
extension AppDelegate {
static func getDelegate() -> AppDelegate {
return UIApplication.shared.delegate as! AppDelegate
}
}
func setScreenAsRoot() {
guard let window = AppDelegate.getDelegate().window else {
return
}
// Loads the navigation controller in which Welcome screen is embed in
guard let screen: UINavigationController = WelcomeVC.loadFirstViewController() as? UINavigationController else {
return
}
// Makes that nav controller the root
window.rootViewController = screen
UIView.transition(with: window, duration: 0.5, options: .transitionCrossDissolve, animations: nil, completion: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment