rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
907 stars 95 forks source link

Passing global stateful object around coordinators and views #66

Closed razvanrujoiu closed 1 year ago

razvanrujoiu commented 2 years ago

I have a root coordinator and multiple child coordinators, and i am trying to pass and @EnvironmentObject around to the child coordinators to pass it further to the child views but i’m getting this warning: “Accessing StateObject’s object without being installed on a View. This will create a new instance each time”. How can i pass a global stateful object around whitout getting this?

zhouxl commented 2 years ago

also

lonkly commented 2 years ago

I use the ObservableObject instead.

LePips commented 1 year ago

This is not a proper use case of StateObject or, frankly, dependency injection and not a Stinsen issue.

https://www.avanderlee.com/swiftui/stateobject-observedobject-differences/