Binding objects using @Bindable
Let’s start with a short recap of what binding is.
In some cases, a view and its child must share a state and create a two-way connection for reading and modifying a value. To do that, we use something called binding.
One classic example is TextField – a TextField view is a SwiftUI component with a text variable. Both TextField and its parent view share the same value of text. Therefore, it’s a binding variable:
struct ContentView: View {
@State var email: String = ""
var body: some View {
VStack {
TextField("Email", text: $email)
}
}
} We see that the email variable is marked as a state, but the TextField view is the one that updates it. The binding occurs using...