I am currently working on SwiftUI app in which I am using SceneDelegate
and AppDelegate
. I would like to know how I can convert the life cycle from
Set the environment on the ContentView as follows:
import SwiftUI
import CoreData
@main
struct MasterDetailApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView().environment(\.managedObjectContext, appDelegate.persistentContainer.viewContext)
}
}
}