Binding
@propertyWrapper
@dynamicMemberLookup
public struct Binding<Value>
A binding is a reference to a value. It does not represent a source
of truth, but it acts as a proxy being able to read and modify the
original value. Reading it’s wrappedValue
from a view’s body will
trigger a subscription from the view to changes in the originally referenced
value.
-
Declaration
Swift
public init(get: @escaping () -> Value, set: @escaping (Value) -> Void)
-
The value referenced by the binding. Assignments to the value will be immediately visible on reading (assuming the binding represents a mutable location), but the view changes they cause may be processed asynchronously to the assignment.
Declaration
Swift
public var wrappedValue: Value { get nonmutating set }
-
The binding value, as “unwrapped” by accessing
$foo
on a@Binding
property.Declaration
Swift
public var projectedValue: Binding<Value> { get }
-
Creates a new
Binding
focused onSubject
using a key path.Declaration
Swift
public subscript<Subject>(dynamicMember keyPath: WritableKeyPath<Value, Subject>) -> Binding<Subject> { get }