Generic Structure

EnvironmentObject

A property wrapper type for an observable object supplied by a parent or ancestor view.

Declaration

@frozen @propertyWrapper struct EnvironmentObject<ObjectType> where ObjectType : ObservableObject

Overview

An environment object invalidates the current view whenever the observable object changes. If you declare a property as an environment object, be sure to set a corresponding model object on an ancestor view by calling its environmentObject(_:) method.

Topics

Creating an Environment Object

init()

Creates an environment object.

Getting the Value

var wrappedValue: ObjectType

The underlying value referenced by the environment object.

var projectedValue: EnvironmentObject<ObjectType>.Wrapper

A projection of the environment object that creates bindings to its properties using dynamic member lookup.

struct EnvironmentObject.Wrapper

A wrapper of the underlying environment object that can create bindings to its properties using dynamic member lookup.

Updating the Value

func update()

Updates the underlying value of the environment object.

Relationships

Conforms To

See Also

Environment Data

struct Environment

A property wrapper type that reads a value from the view’s environment.

struct EnvironmentValues

A collection of environment values propagated through a view hierarchy.