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