iOS 13: Swift - 'Set application root view controller programmatically' does not work

Krunal picture Krunal · Sep 24, 2019 · Viewed 34.1k times · Source

I have following code in my AppDelegate.swift to setup root view controller for an iOS application. But it does not work. It follows Target structure (defined under General tab) and ignores this code.

(Xcode 11, Swift 5.1, iOS 13)

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        window = UIWindow(frame: UIScreen.main.bounds)
        guard let rootVC = UIViewController() else {
            print("Root VC not found")
            return true
        }
        let rootNC = UINavigationController(rootViewController: rootVC)
        window?.rootViewController = rootNC
        window?.makeKeyAndVisible()

        return true
    }
}

Unable to understand where is the issue.

I tried following references also but no luck:

Answer

Carlos García picture Carlos García · Feb 20, 2020

To choose a previous approach to the one supported by SwiftUI, from a project created in Xcode 11, you can follow these steps.

Steps for get old aproach