代码拉取完成,页面将自动刷新
@UIApplicationDelegateAdaptor
属性包装器?如果需要访问 SwiftUI
中的 AppDelegate
功能,则应创建一个继承自 NSObject
和 UIApplicationDelegate
的类,并为其提供所需的任何功能,例如:
class AppDelegate: NSObject, UIApplicationDelegate {
// add app delegate methods here
}
例如,如果您想实现旧的 didFinishLaunchingWithOptions
方法,则可以使用以下方法:
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("Your code here")
return true
}
}
一旦有了,在主应用程序中使用 UIApplicationDelegateAdaptor
属性包装器,以便 SwiftUI
知道创建和管理您的应用程序委托类:
@main
struct NewIn14App: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。