Correctly Adjust @FetchRequest with @SceneStorage + Backgrounding with Core Data+SwiftUI

Hi,

With iOS 15 we can now update the nsPredicate and nsSortDescriptors properties on a @FetchRequest which is great.

What I'm wondering though is the correct way to apply/re-apply user data stored in @State and/or @SceneStorage for predicates when a view is init'd.

Something like @SceneStorage isn't available in the init method but I find that onAppear isn't called in some circumstances.

For example, let's say I have a picker that drives the NSPredicate and the user picks a non-default value. If the app goes into the background and then back to the foreground and that same view is visible, it looks like SwiftUI re-runs the init for the view but does not re-run the onAppear modifier, leaving my UI in an inconsistent state.

What's the right way to handle this? Feels like I must be fighting the framework / there must be a better way.

Correctly Adjust @FetchRequest with @SceneStorage + Backgrounding with Core Data+SwiftUI
 
 
Q