Generic Structure

Published

A type that publishes a property marked with an attribute.

Declaration

@propertyWrapper struct Published<Value>

Overview

Publishing a property with the @Published attribute creates a publisher of this type. You access the publisher with the $ operator, as shown here:

class MyFoo {
    @Published var bar: String
    init(bar: String) {
        self.bar = bar
    }
}
let foo = MyFoo(bar: "bar")
let barSink = foo.$bar
    .sink() {
        print("bar value: \($0)")
}

Topics

Creating a Published Instance

init(initialValue: Value)

Creates a publisher with the provided initial value.

Publishing the Value

var projectedValue: Published<Value>.Publisher

The property for which this instance exposes a publisher.

struct Published.Publisher

A publisher for properties marked with an attribute.

See Also

Publishers

protocol Publisher

Declares that a type can transmit a sequence of values over time.

enum Publishers

A namespace for types that serve as publishers.

struct AnyPublisher

A type-erasing publisher.

protocol ConnectablePublisher

A publisher that provides an explicit means of connecting and canceling publication.

protocol Cancellable

A protocol indicating that an activity or action supports cancellation.

class AnyCancellable

A type-erasing cancellable object that executes a provided closure when canceled.