One Logo Pool Ball
Combine · IOS API REFERENCE

Published

struct · iOS 13.0+ · SDK 27.1

@propertyWrapper struct Published<Value>

A type that publishes a property marked with an attribute. Publishing a property with the `@Published` attribute creates a publisher of this type. You access the publisher with the `$` operator, as shown here: class Weather { @Published var temperature: Double init(temperature: Double) { self.temperature = temperature } } let weather = Weather(temperature: 20) cancellable = weather.$temperature .sink() { print ("Temperature now: \($0)") } weather.temperature = 25 // Prints: // Temperature now: 20.0 // Temperature now: 25.0 When the property changes, publishing occurs in the property's `willSet` block, meaning subscribers receive the new value before it's actually set on the property. In the above example, the second time the sink executes its closure, it receives the parameter value `25`. However, if the closure evaluated `weather.temperature`, the value returned would be `20`. > Important: The `@Published` attribute is class constrained. Use it with properties of classes, not with non-class types like structures. ### See Also - ``Combine/Publisher/assign(to:)``

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Published.projectedValue

The iOS SDK compiler rejected this binding: cannot use mutating getter on immutable value: 'o' is a 'let' constant

All Combine types →