State
-
A binding is a reference to a value. It does not represent a source of truth, but it acts as a proxy being able to read and modify the original value. Reading it’s
See morewrappedValuefrom a view’s body will trigger a subscription from the view to changes in the originally referenced value.Declaration
Swift
@propertyWrapper @dynamicMemberLookup public struct Binding<Value> -
References and observes environment values set by the framework.
Currently supported environment values are:
- presentationMode
Declaration
Swift
@propertyWrapper public class Environment<Value> : DynamicProperty -
Used to reference and observe environment objects previously set. Environment objects are identified by their type, meaning only one of the same type can exist at a time as an environment object.
See moreImportant
Referencing an environment object not previously set will trigger an exception.Declaration
Swift
@propertyWrapper public class EnvironmentObject<ObjectType> : DynamicProperty where ObjectType : ObservableObject -
Used to observe an
See moreObservableObjectwhen changes to itsPublishedproperties occur.Declaration
Swift
@propertyWrapper public class ObservedObject<ObjectType> where ObjectType : ObservableObject -
A type that publishes a property.
When the wrapped value of a published type changes, views that have accessed to its parent
ObservableObjectthrough a@ObservedObjectproperty, will receive render updates.See moreImportant
Published types should be used only inObservableObjectclasses.Declaration
Swift
@propertyWrapper public class Published<Value> : ChildWrapper -
Represents a mutable value to be held by a
View. Reading a state’swrappedValueproperty inside a view’sbodycomputed property will trigger a subscribption by the view to listen to changes in the state’s value.See moreImportant
You shouldn’t modify a state’s wrapped value when the view’sbodyproperty is being read.Declaration
Swift
@propertyWrapper public class State<Value> -
StateObject works similarly as ObservedObject, with the only difference that for being part of a view’s state, if the view is recreated while owning an object, the object won’t be recreated and will keep it’s previous data.
On view recreation (by a state change in its parent):
- ObservedObject owned by view: Gets recreated (re-initialized)
- StateObject owned by view: Keeps same instance
Declaration
Swift
@propertyWrapper public class StateObject<ObjectType> where ObjectType : ObservableObject
View on GitHub
State Reference