Repository Public MIT
1# GlassModelPicker23| | |4|---|---|5| Identifier | `glass-model-picker` |6| Module | `SPGlassAI` |7| Kind | `native-wrapper` — the system draws the `Menu` and its rows |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/AI/GlassModelPickerExample.swift` |1011UI only: the list of models and their states are supplied by the host. The picker downloads nothing and contacts no provider.1213## Minimal usage1415```swift16@State private var modelID: String? = "small"1718GlassModelPicker(models: models, selection: $modelID)19```2021## Variants2223| Availability | Row |24|---|---|25| `.local` | "On device · Text, Vision" |26| `.remote` | "Remote · Text, Tools" |27| `.unavailable(reason:)` | Disabled, "Unavailable · Not downloaded" |2829Models are grouped in sections by `provider`. The menu's label is the selected model's name with a symbol for where it runs, or the title when nothing is selected.3031## Parameters3233| Parameter | Type | Default | Meaning |34|---|---|---|---|35| `title` | `LocalizedStringKey?` | "Model" | Accessibility label, and visible title when nothing is selected. |36| `models` | `[GlassModelInfo]` | — | `id`, `name`, `provider`, `capabilities`, `availability`. Any order. |37| `selection` | `Binding<String?>` | — | Identifier of the selected model. |3839`GlassModelCapabilities` is an option set: `.text`, `.vision`, `.tools`, `.reasoning`, `.audio`, `.code`. Each has a localised name and a symbol (`descriptors`) for hosts that draw their own summary.4041## States4243- **Selected**: the row carries the system checkmark (each row is a `Toggle` inside the menu).44- **Unavailable**: the row is disabled and gives the reason in words.45- **No selection**: the label shows the title.46- **Empty list**: the menu is disabled.4748Sorting and grouping are `GlassModelCatalog.grouped(_:)`: providers alphabetically; inside a provider, selectable models first, then by name with numeric-aware comparison; a repeated identifier keeps its first occurrence.4950## Advanced example5152```swift53struct ModelToolbarItem: ToolbarContent {54 let registry: ModelRegistry // host type55 @Binding var selection: String?5657 var body: some ToolbarContent {58 ToolbarItem(placement: .principal) {59 GlassModelPicker("Model", models: registry.models.map { model in60 GlassModelInfo(61 id: model.id,62 name: model.displayName,63 provider: model.vendor,64 capabilities: model.supportsImages ? [.text, .vision] : [.text],65 availability: model.isDownloaded ? .local : .unavailable(reason: "Not downloaded")66 )67 }, selection: $selection)68 }69 }70}71```7273## Accessibility7475- The menu is labelled with the title; its value is the selected model's name, where it runs and its capabilities.76- Capabilities and availability are written in words in every row; symbols are never the only carrier.77- Unavailable rows are disabled by the system and state the reason.78- Everything else (keyboard navigation, VoiceOver, Dynamic Type) is the system menu's behaviour.7980## Limits8182- How a second line of text is displayed in a menu row is decided by the platform; the text is always available to assistive technologies.83- The picker does not validate that `selection` exists in `models`; an unknown identifier shows the title.84- No search field: for long catalogues present a searchable list in a sheet instead.85- The rendering of the menu was not inspected in a running application during verification; grouping, sorting and wording are unit-tested.86