Help - I'm trying to "improve" the structure of my iOS app by splitting it down into multiple source files and have only succeeded in breaking it!
In the top-level app I have an @StateObject and I pass this as a .environmentObject into my ContentView
I have the @EnvironmentObject defined in my ContentView
That part all looks good to me.
I have a .onAppear{myFunction()} on the ContentView body.
The onAppear fires correctly and myFunction() gets called.
myFunction() retrieves a file from a remote website. This also works correctly - I can print() the contents of the file.
So, at this point I have the data I need sitting inside myFunction() but I simply cannot figure how to then update the @StateObject from within myFunction() so that the ContentView gets refreshed via its @EnvironmentObject ...
In summary:
func myFunction() {
fetch file from website <-- works fine
update @StateObject in top-level app with file content <-- cannot get this working
}
Can anyone point me towards a solution?
Many thanks!