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

后端 未结 14 1056
北恋
北恋 2020-12-01 01:43

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

14条回答
  •  情深已故
    2020-12-01 02:29

    For Xcode 11+ and Swift 5+ inside SceneDelegate.swift

    
    var window: UIWindow?
    
        func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
            if let windowScene = scene as? UIWindowScene {
                let window = UIWindow(windowScene: windowScene)
                let submodules = (
                    home: HomeRouter.createModule(),
                    search: SearchRouter.createModule(),
                    exoplanets: ExoplanetsRouter.createModule()
                )
                
                let tabBarController = TabBarModuleBuilder.build(usingSubmodules: submodules)
                
                window.rootViewController = tabBarController
                self.window = window
                window.makeKeyAndVisible()
            }
        }
    

提交回复
热议问题