I have something like this:
struct Main: View { @ObservedObject var data: Data = Data() @ObservedObject var profiles: Profiles = Profiles() var body: some View { TabView{ Discover().tabItem { Image(systemName: "book") Text("Discover") } // more tabs } } } My issue is that this data and profiles are bound to a database and initiated when the app starts. When the app gets started and no user is logged in there will be no data accessed. As the data is user specific content on the Database (Firestore).
Now when logging in the data doesn't appear until a restart of the app as the vars have already been initiated with empty database content. As content is bound to the user.
Id need to reinitiate them or "refetch" them once the users logs in or a user is logged in. Doing this with onAppear is not optimal as this would drive the database traffic up.
I use Firestore as my database.
Auth.auth().addStateDidChangeListener { (auth, user) }