One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

Bindable

struct · iOS 17.0+ · SDK 27.1

@dynamicMemberLookup @propertyWrapper struct Bindable<Value>

A property wrapper type that supports creating bindings to the mutable properties of observable objects. Use this property wrapper to create bindings to mutable properties of a data model object that conforms to the <doc://com.apple.documentation/documentation/Observation/Observable> protocol. For example, the following code wraps the `book` input with `@Bindable`. Then it uses a ``TextField`` to change the `title` property of a book, and a ``Toggle`` to change the `isAvailable` property, using the `$` syntax to pass a binding for each property to those controls. @Observable class Book: Identifiable { var title = "Sample Book Title" var isAvailable = true } struct BookEditView: View { @Bindable var book: Book @Environment(\.dismiss) private var dismiss var body: some View { Form { TextField("Title", text: $book.title) Toggle("Book is available", isOn: $book.isAvailable) Button("Close") { dismiss() } } } } You can use the `Bindable` property wrapper on properties and variables to an <doc://com.apple.documentation/documentation/Observation/Observable> object. This includes global variables, properties that exists outside of SwiftUI types, or even local variables. For example, you can create a `@Bindable` variable within a view's ``View/body-swift.property``: struct LibraryView: View { @State private var books = [Book(), Book(), Book()] var body: some View { List(books) { book in @Bindable var book = book TextField("Title", text: $book.title) } } } The `@Bindable` variable `book` provides a binding that connects ``TextField`` to the `title` property of a book so that a person can make changes directly to the model data. Use this same approach when you need a binding to a property of an observable object stored in a view's environment. For example, the following code uses the ``Environment`` property wrapper to retrieve an instance of the observable type `Book`. Then the code creates a `@Bindable` variable `book` and passes a binding for the `title` property to a ``TextField`` using the `$` syntax. struct TitleEditView: View { @Environment(Book.self) private var book var body: some View { @Bindable var book = book TextField("Title", text: $book.title) } }

Members (0)

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

Skipped declarations

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

Bindable.subscript(dynamicMember:)

The iOS SDK compiler rejected this binding: referencing subscript 'subscript(dynamicMember:)' on 'Bindable' requires that 'Any' be a class type

Bindable.init(wrappedValue:)

This declaration needs Swift generic type arguments. (no canonical witness for Value)

Bindable.init(_:)

This declaration needs Swift generic type arguments. (no canonical witness for Value)

Bindable.init(projectedValue:)

The containing type needs Swift generic type arguments. (no canonical witness for Value)

Bindable.id

This declaration needs Swift generic type arguments. (no canonical witness for Value.ID)

All SwiftUICore types →