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.

Beta
enum Publishers

A namespace for types that serve as publishers.

Beta
struct AnyPublisher

A type-erasing publisher.

Beta
protocol ConnectablePublisher

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

Beta
protocol Cancellable

A protocol indicating that an activity or action supports cancellation.

Beta
class AnyCancellable

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

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software