WWDC2020SwiftUI教程与源码

SwiftUI 2.0 SwiftUIApp模式如何使用UIAp

2020-06-25  本文已影响0人  iCloudEnd

WWDC2020 变化

如果您仍然需要监听UIApplicationDelegate的任何委托回调,SwiftUI将提供一个到UIApplicationDelegateAdaptor

基础知识

UIApplicationDelegateAdaptor

App中用于提供UIKit委托的属性包装器

@propertyWrapper struct UIApplicationDelegateAdaptor<DelegateType> where DelegateType : NSObject, DelegateType : UIApplicationDelegate

实战代码

import SwiftUI

class AppDelegate:NSObject,UIApplicationDelegate{
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        print("I am back")
        return true
    }
}

@main
struct sf2_appdelegateApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

技术交流

QQ:3365059189
SwiftUI技术交流QQ群:518696470

上一篇 下一篇

猜你喜欢

热点阅读