Bidirectional binding with Picker
In this section, we will use Picker
and a bound state variable to allow the user to choose one color from a group of five choices. Take a look at the following example:
import SwiftUI struct StateWithPicker: View { private let colors = ["White", "Red", "Blue", "Green", "Black"] @State private var color = "White" var body: some View { VStack(spacing: 15) { Spacer() Text("Choose your color by name") Picker("Name", selection: $color) { ForEach(colors, id: \.self) { name in ...