Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save richimf/f4572ca15994375f7307179598d96dd8 to your computer and use it in GitHub Desktop.
Save richimf/f4572ca15994375f7307179598d96dd8 to your computer and use it in GitHub Desktop.
Add navigation Stack programatically Swift
// APPDELEGATE:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let nvc = UINavigationController(rootViewController: ViewController())
window?.rootViewController = nvc
return true
}
// SCENEDELEGATE:
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.makeKeyAndVisible()
let nvc = UINavigationController(rootViewController: ViewController())
window?.rootViewController = nvc
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment