ObjectState

@propertyWrapper
public struct ObjectState<O> : DynamicProperty where O : DynamicObject

A property wrapper type that can read ObjectPublisher changes.

Public

  • Creates an instance that observes ObjectPublisher changes and exposes an Optional<ObjectSnapshot<O>> value.

    @ObjectState
    var person: ObjectSnapshot<Person>?
    
    init(objectPublisher: ObjectPublisher<Person>) {
    
       self._person = .init(objectPublisher)
    }
    
    var body: some View {
    
       HStack {
    
           AsyncImage(self.person?.$avatarURL)
           Text(self.person?.$fullName ?? "")
       }
    }
    

    Declaration

    Swift

    public init(_ objectPublisher: ObjectPublisher<O>?)

    Parameters

    objectPublisher

    The ObjectPublisher that the ObjectState will observe changes for

DynamicProperty

  • Declaration

    Swift

    public mutating func update()