GlassPicker
| Identifier | glass-picker |
| Module | SPGlassForms |
| Kind | native-wrapper — the system Picker with a platform-appropriate style |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Selection/GlassPickerExample.swift |
Minimal usage
swift
@State private var currency = "CAD"
GlassPicker("Currency", selection: $currency, options: ["CAD", "EUR", "USD"])Variants
presentation |
iOS and iPadOS | macOS |
|---|---|---|
.menu (default) |
Pop-up menu | Pop-up button |
.wheel |
Wheel | Pop-up button (no wheel on macOS) |
.inline |
Inline list of options | Radio buttons |
Options can be named three ways: by themselves (CustomStringConvertible, as above), by a closure or key path (title: \.name), or by a view builder for rows with a symbol.
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
title |
LocalizedStringKey |
— | Label of the picker. |
selection |
Binding<Option> |
— | Selected option. Option is any Hashable type. |
options |
[Option] |
— | Options in order. |
presentation |
GlassPickerPresentation |
.menu |
Menu, wheel or inline. |
title: |
(Option) -> String |
— | Name of an option. |
optionLabel |
@ViewBuilder (Option) -> View |
— | Custom label of an option. |
States
The selected option, the open menu, focus and the disabled state (.disabled(_:)) are drawn by the system.
Advanced example
swift
struct Plan: Hashable { let name: String; let symbol: String }
GlassPicker("Plan", selection: $plan, options: plans) { plan in
Label(plan.name, systemImage: plan.symbol)
}
GlassPicker("Reminder", selection: $hour, options: Array(6...22), presentation: .wheel, title: { hour in
"\(hour.formatted(.number.precision(.integerLength(2)))):00"
})GlassPickerPresentation.wheel.resolved(for: .macOS) returns .menu: the mapping is a pure function.
Accessibility
- The picker is a system control: label, current value, the list of options and keyboard navigation come from the system.
- Option labels built with
Labelkeep their text for VoiceOver. - Long option names wrap in the inline presentation and are shown in full in menus.
Limits
optionsmust contain the current selection, as with anyPicker; otherwise nothing appears selected.- Options must be unique (
Hashableidentity is used). - The wheel exists only on iOS and iPadOS, radio buttons only on macOS.
- Single selection only.