我正在将一个SwiftUI iOS应用移植到macOS上。它使用@UIApplicationDelegateAdaptor属性包装器来绑定UIApplicationDelegate类。不幸的是,UIApplicationDelegate类在macOS上不可用,所以我想知道如何绑定我的自定义AppDelegate。
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
...
}
}
struct MyApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
...
}
}