使用SwiftUI 2.0和Core data预填充数据



当应用程序第一次加载时,如何在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
}
}

然后在您的@mainView中添加。

@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

适用于iOS或

class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {

}

}

@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

适用于MacOS

最新更新