当应用程序第一次加载时,如何在SwiftUI 2.0中将json中的数据预填充到核心数据中。在SwiftUI 1.0中,我在AppDelegate.swift
中做了这件事,但现在已经没有这样的文件了。
添加您自己的AppDelegate.swift
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
}
然后在您的@main
View
中添加。
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
适用于iOS或
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
}
}
和
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
适用于MacOS