How to convert from UIKit life cycle to SwiftUI life cycle in iOS 14 (Xcode 12 Beta)

后端 未结 2 988
花落未央
花落未央 2021-01-02 17:11

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

2条回答
  •  一整个雨季
    2021-01-02 17:48

    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)
            }
        }
    }
    

提交回复
热议问题