SwiftData - different containers in one app

Hello to team, I have a very challenging issue that I'm not able to fix. I have an app that works with SwiftData Model Container that is generated when the app is launched. In the app I also added a Demo Mode area, where the user can load a mock data and simulating app behavior with more data. In order to switch to demo mode, I'm loading new UI layer and loading a new model container, which is configured to work with the same scheme, but isStoredInMemoryOnly = true. Everything works fine.

Now, when the user toggles off the demo mode and go back to the main UI, any persistent changes to the modelContext leads to a crash where it says that the create store is different from the open store. Tried almost everything - I'm not sure even if it's possible to have this flow with SwiftData, butI'm trying.

Please advice.

Thanks a lot!

SwiftData - different containers in one app
 
 
Q