SwiftUI 中重拾AppDelegate

1.新建项目(新建项目时请选择如图选项)

截屏2021-10-23 上午9.21.33.png

2.建完项目后,不出问题的话能看到熟悉的Appdelegete回来了

那如何指定根控制器呢?


截屏2021-10-23 上午9.26.23.png
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`.
        // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
        // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: ContentView())
            self.window = window
            window.makeKeyAndVisible()
        }
       // guard let _ = (scene as? UIWindowScene) else { return }
    }

ContentView 为你自己写的swiftUI
到此工作完成 可以愉快的coding了

你可能感兴趣的:(SwiftUI 中重拾AppDelegate)