Binding
struct · iOS 13.0+ · SDK 27.1
@frozen @propertyWrapper @dynamicMemberLookup struct Binding<Value>A property wrapper type that can read and write a value owned by a source of truth. Use a binding to create a two-way connection between a property that stores data, and a view that displays and changes the data. A binding connects a property to a source of truth stored elsewhere, instead of storing data directly. For example, a button that toggles between play and pause can create a binding to a property of its parent view using the `Binding` property wrapper. struct PlayButton: View { @Binding var isPlaying: Bool var body: some View { Button(isPlaying ? "Pause" : "Play") { isPlaying.toggle() } } } The parent view declares a property to hold the playing state, using the ``State`` property wrapper to indicate that this property is the value's source of truth. struct PlayerView: View { var episode: Episode @State private var isPlaying: Bool = false var body: some View { VStack { Text(episode.title) .foregroundStyle(isPlaying ? .primary : .secondary) PlayButton(isPlaying: $isPlaying) // Pass a binding. } } } When `PlayerView` initializes `PlayButton`, it passes a binding of its state property into the button's binding property. Applying the `$` prefix to a property wrapped value returns its ``State/projectedValue``, which for a state property wrapper returns a binding to the value. Whenever the user taps the `PlayButton`, the `PlayerView` updates its `isPlaying` state. A binding conforms to ``Sendable`` only if its wrapped value type also conforms to ``Sendable``. It is always safe to pass a sendable binding between different concurrency domains. However, reading from or writing to a binding's wrapped value from a different concurrency domain may or may not be safe, depending on how the binding was created. SwiftUI will issue a warning at runtime if it detects a binding being used in a way that may compromise data safety. > Note: To create bindings to properties of a type that conforms to the <doc://com.apple.documentation/documentation/Observation/Observable> protocol, use the ``Bindable`` property wrapper. For more information, see <doc:Migrating-from-the-observable-object-protocol-to-the-observable-macro>.
Members (0)
This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.
Skipped declarations
11 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.
Binding.init(get:set:)
callback cannot propagate synchronous failure
Binding.init(get:set:)
callback cannot propagate synchronous failure
Binding.id
This declaration needs Swift generic type arguments. (no canonical witness for Value.ID)
Binding.startIndex
The containing type needs Swift generic type arguments. (no canonical witness for Value)
Binding.endIndex
The containing type needs Swift generic type arguments. (no canonical witness for Value)
Binding.indices
This declaration needs Swift generic type arguments. (no canonical witness for Value.Indices)
Binding.index(after:)
The containing type needs Swift generic type arguments. (no canonical witness for Value)
Binding.formIndex(after:)
The containing type needs Swift generic type arguments. (no canonical witness for Value)
Binding.subscript(_:)
The containing type needs Swift generic type arguments. (no canonical witness for Value)
Binding.index(before:)
The containing type needs Swift generic type arguments. (no canonical witness for Value)
Binding.formIndex(before:)
The containing type needs Swift generic type arguments. (no canonical witness for Value)