You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using your package in a project and I noticed that Xcode gives the warning:
"Accessing StateObject's object without being installed on a View. This will create a new instance each time."
at the point where self.viewModel.download() is called, inside a view initialiser.
That's happening because the download is being initiated when the view is initialised rather than when it's added to the view hierarchy. I think you should consider fixing your implementation by moving all the self.viewModel.download() calls out of the initialisers they're in and into a closure passed to an onAppear() view modifier, like so:
init(viewModel:ViewModel,@ViewBuilder content:@escaping(AsyncImagePhase)->Content){self._viewModel =.init(wrappedValue: viewModel)self.content = content
// self.viewModel.download() // <--- remove this line}varbody:someView{content(viewModel.phase).onAppear{ viewModel.download()}// <--- add this line}
In any case, thanks for writing this package.
The text was updated successfully, but these errors were encountered:
Hello.
I'm using your package in a project and I noticed that Xcode gives the warning:
"Accessing StateObject's object without being installed on a View. This will create a new instance each time."
at the point where
self.viewModel.download()
is called, inside a view initialiser.That's happening because the download is being initiated when the view is initialised rather than when it's added to the view hierarchy. I think you should consider fixing your implementation by moving all the
self.viewModel.download()
calls out of the initialisers they're in and into a closure passed to anonAppear()
view modifier, like so:In any case, thanks for writing this package.
The text was updated successfully, but these errors were encountered: