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 wrappedValue from a view’s body will trigger a subscription from the view to changes in the originally referenced value.

    See more

    Declaration

    Swift

    @propertyWrapper
    @dynamicMemberLookup
    public struct Binding<Value>
  • References and observes environment values set by the framework.

    Currently supported environment values are:

    • presentationMode
    See more

    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.

    Important

    Referencing an environment object not previously set will trigger an exception.
    See more

    Declaration

    Swift

    @propertyWrapper
    public class EnvironmentObject<ObjectType> : DynamicProperty where ObjectType : ObservableObject
  • Used to observe an ObservableObject when changes to its Published properties occur.

    See more

    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 ObservableObject through a @ObservedObject property, will receive render updates.

    Important

    Published types should be used only in ObservableObject classes.
    See more

    Declaration

    Swift

    @propertyWrapper
    public class Published<Value> : ChildWrapper
  • Represents a mutable value to be held by a View. Reading a state’s wrappedValue property inside a view’s body computed property will trigger a subscribption by the view to listen to changes in the state’s value.

    Important

    You shouldn’t modify a state’s wrapped value when the view’s body property is being read.
    See more

    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
    See more

    Declaration

    Swift

    @propertyWrapper
    public class StateObject<ObjectType> where ObjectType : ObservableObject