๐ธenvironment object
SwiftUI โฉ view โฉ environment โฉ object
An environment object is a state object, which is
initialized in an ancester view by adding a @StateObject property
and put in the environment by calling the ancester view's .environmentObject(_:) modifier.
To use an environment object In a subview, declare a corrspoinding @EnvironmentObject property in the subview.
Be sure to set a corresponding model instance on an ancester view by calling its .environmentObject(_:) modifier.
ObservableObject๏ผdeclare an observable object type.
@Published๏ผdeclare published values in an observable object type.
@StateObject๏ผinitialize an observable object.
Use .environmentObject(_:) to put the model object in the environment.
Use @EnvironmentObject to declare an observable object property provided by an ancestor view.
observer๏ผ any view or object that uses the observable object's data.
data model๏ผdata shared with any views in your app.
Last updated