Selecting Options with Picker
Offer choices with menu and segmented pickers.
Selecting Options with Picker is a free SwiftUI Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Meet the Picker
A Picker lets users choose one option from several. It is the go-to for selecting a category, color, or plan. 📋
Picker Tracks a Selection
A Picker stores the selected value in state. As the user chooses, that bound property updates to match.
@State private var fruit = "Apple"Bind the Selection
Pass a label and the selection binding so the Picker knows which property to read and update.
Picker("Fruit", selection: $fruit) {
// options go here
}List the Options
Inside the closure, add a view per choice and tag each with its value using tag so selection can match it.
Text("Apple").tag("Apple")
Text("Pear").tag("Pear")Loop with ForEach
For many options, generate them with ForEach over an array instead of writing each row by hand.
ForEach(fruits, id: \.self) { name in
Text(name).tag(name)
}Match Selection Types
The selection type must match the tag type. If you select a String, every tag must also be a String.
The Menu Style
Apply pickerStyle to change the look. The menu style shows the choice and pops options on tap.
Picker("Fruit", selection: $fruit) { }
.pickerStyle(.menu)The Segmented Style
For a few short options, the segmented style lays them out as a row of side-by-side buttons.
.pickerStyle(.segmented)The Wheel Style
The wheel style shows a spinning drum, classic for dates or long lists where scrolling feels natural.
.pickerStyle(.wheel)React to the Choice
Read the bound value anywhere to react to the user's pick, like showing the selected fruit in a Text.
Text("You picked \(fruit)")The Full View
Here is a complete Picker: a selection binding, options from ForEach, and the segmented style applied.
struct ChooseView: View {
@State private var fruit = "Apple"
let fruits = ["Apple", "Pear"]
var body: some View {
Picker("Fruit", selection: $fruit) {
ForEach(fruits, id: \.self) { Text($0).tag($0) }
}
}
}Quick Check
Why must each Picker option be tagged?
Recap
A Picker binds to a selection, tags each option, and changes look with menu, segmented, or wheel styles. 📋
Frequently asked questions
Is the “Selecting Options with Picker” lesson free?
Yes — the full text of “Selecting Options with Picker” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “Selecting Options with Picker”?
Offer choices with menu and segmented pickers. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Selecting Options with Picker” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- On/Off with Toggle
- Choosing Values with Slider
- Incrementing with Stepper
- Selecting Options with Picker