- Here is what I thought
I want to give each user a unique container, when the user login or register, the user could isolate their data in specific container.
I shared the container in a singleton actor, I found it's possible to update the container in that actor.
But I think it won't affect the modelContext which is in the Environment.
Does SwiftData allow me or recommend to do that?
Technically, it's totally fine that your app replaces an existing model container with a new one, or use multiple containers. Just be sure that you update with the appropriate container for your views and scene via their modelContainer(_:) method. When that is done, the model context injected to the environment of the view hierarchy should change automatically, which triggers an update for the view hierarchy.
Practically, I'd probably only do that if every user has their own store (so I need to switch to another store when a user login happens). Sharing one single model container across an app is good enough for most cases, and makes things simpler.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.