SwiftUI篇-1 项目结构

作者: 浪人残风 | 来源:发表于2021-02-24 09:58 被阅读0次

    摘要:

    介绍Xcode新建的SwiftUI模版项目结构、跟普通Storyboard模版项目的差异、SwiftUI项目的app启动流程、UIScene概念介绍、AppDelegate.swift和Info.plist的差异

    1.项目模版

    Interface: SwiftUI

    Life Cycle: UIKit App Delegate

    Language: Swift

    Life Cycle选择UIKit App Delegate是为了项目模版有app生命周期,方便跟普通app生命周期做比较

     2.差异性

    1)AppDelegate.swift

    import UIKit

    @main

    class AppDelegate: UIResponder, UIApplicationDelegate {

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

            // Override point for customization after application launch.

            return true

        }

        // MARK: UISceneSession Lifecycle

        func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {

            // Called when a new scene session is being created.

            // Use this method to select a configuration to create the new scene with.

            return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)

        }

        func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

            // Called when the user discards a scene session.

            // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.

            // Use this method to release any resources that were specific to the discarded scenes, as they will not return.

        }

    }

    app原本的生命周期不见了?增加了UISceneSession的生命周期!

    swiftUI增加了Scene场景的概念,app可以切换scene场景

    scene场景:pc电脑或某些iPad可以在一个app软件里面打开多个window窗口,一个window窗口就是对应一个scene场景,如火狐浏览器可以同时打开多个窗口,一个窗口显示百度首页,一个窗口显示火狐首页,如下:

    相关文章

      网友评论

        本文标题:SwiftUI篇-1 项目结构

        本文链接:https://www.haomeiwen.com/subject/tjwjfltx.html