Best practices for preserving data between app launches for SwiftUI

I understand how to use Codable to serialize data, how to read and write to UserDefaults, and that SwiftUI provides events like "sceneWillResignActive" and "sceneWillEnterForeground".

What I am missing is how to tie all of this together - what are the best practices for preserving data between app launches for SwiftUI?

It feels like I should capture important data values and write them during the Scene's lifecycle events. Can someone highlight an article or post that clarifies this?

Thank you.
Take a look at @SceneStorage.
There are some good references online to the SceneStorage addition to SwiftUI, and it seems a great solution for basic scene restoration. There are some significant caveats that imply we will must have a mastery of the app's lifecycle to save and restore application data. Coming from UIKit we would tap into Appdelegate events... I am unclear what is the right way within this framework.
Nevermind preserving between launches - what about preserving state when switching between views - simple things like a list view forgets what item was selected and what its scroll position was.
@duncang I think SceneStorage is what you want

For anyone else reading this thread, I am going to go with saving context in sceneDidEnterBackground and loading context in scene.willConnectTo

I feel like I should also be hooking into sceneWillEnterForeground but so far in my testing I haven't needed to.
Best practices for preserving data between app launches for SwiftUI
 
 
Q