To reduce boilerplate code, I want to use the new SwiftUI Lifecycle in iOS 14 to replace AppDelegate and SceneDelegate. But how to Listen to SceneDelegate Lifecycle Methods?
For example:
How to save changes in the application's managed object context when the application transitions to the background?
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
let persistenceController = PersistenceController.shared
...
func sceneDidEnterBackground(_ scene: UIScene) {
persistenceController.saveContext()
}
}