Last active
May 20, 2021 21:40
-
-
Save jong9000/72f9a62c9275eea281facba247339977 to your computer and use it in GitHub Desktop.
Scene Delegate with Programmatic UINavigationController
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
import UIKit | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. | |
// 1. Create named variable for the window scene. | |
guard let windowScene = (scene as? UIWindowScene) else { return } | |
// 2. Set class `window` property to newly created window that is associated to the `windowScene` object. | |
window = UIWindow(windowScene: windowScene) | |
// 3. Instnatiate your view controller and designate it as the root view controller of a newly instantiated navigation controller. | |
let rootViewController = RootViewController() | |
let navigationController = UINavigationController(rootViewController: rootViewController) | |
// 4. Designate the navigation controller as the root view controller of the window. | |
window?.rootViewController = navigationController | |
// 5. Set window as the key window and show window. | |
window?.makeKeyAndVisible() | |
} | |
/* | |
. | |
. | |
. | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment