GlassPicker
Generic picker over Hashable options, as a menu or a wheel depending on the platform.
- System control
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-picker
Drawn by the system. GlassKit configures it and leaves the glass to the system.
CaptureInstallation
spglass add glass-pickerCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| 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
@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
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.- On iOS and iPadOS the menu presentation is a row: the title on the leading side, the system menu button on the trailing side (since 1.1; the system picker alone shows only its value outside a
Form). - Options must be unique (
Hashableidentity is used). - The wheel exists only on iOS and iPadOS, radio buttons only on macOS.
- Single selection only.
Example
import SwiftUI
import SPGlassKit
public struct GlassPickerExample: GlassExample {
public static let componentID = "glass-picker"
struct Plan: Hashable {
let name: String
let symbol: String
}
private static let plans = [
Plan(name: "Starter", symbol: "leaf"),
Plan(name: "Team", symbol: "person.3"),
Plan(name: "Enterprise with a long name", symbol: "building.2"),
]
@State private var plan = GlassPickerExample.plans[0]
@State private var currency = "CAD"
@State private var hour = 9
@State private var priority = "Normal"
public init() {}
public var body: some View {
Form {
GlassPicker("Plan", selection: $plan, options: Self.plans) { plan in
Label(plan.name, systemImage: plan.symbol)
}
GlassPicker("Currency", selection: $currency, options: ["CAD", "EUR", "JPY", "USD"])
GlassPicker("Reminder hour", selection: $hour, options: Array(6...22), presentation: .wheel) { hour in
"\(hour.formatted(.number.precision(.integerLength(2)))):00"
}
GlassPicker("Priority", selection: $priority, options: ["Low", "Normal", "High"], presentation: .inline)
GlassPicker("Region", selection: .constant("Canada"), options: ["Canada"])
.disabled(true)
}
}
}
#Preview("GlassPicker") { GlassPickerExample() }
Registry entry
| Identifier | glass-picker |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassPickerPresentation, Resolved, GlassPicker |
| Licence | MIT |
| Manifest | manifest.json |
Files
Forms/Selection/GlassPicker.swift6338 bytes · sha256 43fa8f538d61…