Last active
June 12, 2019 17:50
-
-
Save rsaenzi/d352a676affc84c9c191f5feb0b9e384 to your computer and use it in GitHub Desktop.
Small function to get the App Delegate of any iOS app
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
| // | |
| // 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