@Binding
Asked on 01/20/2025
1 search
In the context of SwiftUI, @Binding
is a property wrapper that creates a two-way reference to the state of another view. This allows a view to read and write a value that is owned by a different view, enabling synchronization between views. For example, if you have a container view that manages a piece of state, you can pass a binding to a child view, allowing the child view to update the state and reflect those changes in the container view.
In the session "SwiftUI essentials," it is explained how a binding can be used to synchronize state between a container view and its child views, ensuring that they update in sync. This is particularly useful when you want multiple views to reflect the same piece of data without each maintaining its own separate state.
For more details, you can refer to the session SwiftUI essentials (12:29).

SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.

Explore object tracking for visionOS
Find out how you can use object tracking to turn real-world objects into virtual anchors in your visionOS app. Learn how you can build spatial experiences with object tracking from start to finish. Find out how to create a reference object using machine learning in Create ML and attach content relative to your target object in Reality Composer Pro, RealityKit or ARKit APIs.

Migrate your app to Swift 6
Experience Swift 6 migration in action as we update an existing sample app. Learn how to migrate incrementally, module by module, and how the compiler helps you identify code that’s at risk of data races. Discover different techniques for ensuring clear isolation boundaries and eliminating concurrent access to shared mutable state.