SP GlassKit1.1.0

GlassAlert

System alert and confirmation dialog described by a value with correct button roles.

  • System control
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-alert

Drawn by the system. GlassKit configures it and leaves the glass to the system.

GlassAlert running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-alert

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-alert
ModuleSPGlassComponents
Kindnative-wrapper — the system .alert and .confirmationDialog
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Feedback/GlassAlertExample.swift

Minimal usage

Swift
@State private var alert: GlassAlert?

content.glassAlert($alert)

alert = GlassAlert(title: "Export finished")

Variants

VariantUse
style: .alert (default)Modal alert: information to acknowledge, or a decision with one or two choices.
style: .confirmationConfirmation dialog attached to the view: confirming an action the user just started, or choosing among several actions.
GlassAlertButton("Save") { … }Regular button.
.destructive("Delete") { … }Destructive button.
.cancel() / .cancel("Not now") { … }Cancel button; the default title is GlassKit's localised "Cancel".

Parameters

ParameterTypeDefaultMeaning
titleString—Title, already localised by the host.
messageString?nilExplanation.
styleGlassAlertStyle.alertPresentation.
buttons[GlassAlertButton][]Buttons, validated before presentation.
idStringrandom UUIDIdentity.

States

The alert is presented while the bound value is non-nil and the binding is reset to nil on dismissal. Before presentation GlassAlertValidator.validated(_:style:) applies these rules:

  1. Only the first cancel button keeps the cancel role; later ones become regular buttons (their actions are kept).
  2. An alert without buttons gets "OK"; a confirmation without buttons gets "Cancel".
  3. When a destructive button exists and no cancel button does, "Cancel" is added.
  4. Order: regular buttons, then destructive ones, then cancel.

The default action (Return key) is the first regular button, otherwise cancel — never a destructive button (GlassAlertValidator.defaultButtonIndex(in:)).

Advanced example

Swift
func confirmDeletion(of documents: [Document]) {
    alert = GlassAlert(
        title: String(localized: "Delete \(documents.count) documents?"),
        message: String(localized: "They will be removed from all your devices."),
        style: .confirmation,
        buttons: [
            .destructive(String(localized: "Delete")) { store.delete(documents) },
            GlassAlertButton(String(localized: "Move to archive")) { store.archive(documents) },
        ]   // "Cancel" is added by validation
    )
}

Accessibility

  • The system presents the alert: focus moves to it, VoiceOver reads title and message, and roles are announced by the system, not conveyed by colour alone.
  • Escape and the cancel gesture trigger the cancel button, which validation guarantees whenever a destructive action is offered.
  • Titles and messages are plain strings: Dynamic Type and wrapping are the system's.

Limits

  • Titles are String: localise them in the host (String(localized:)). Only the automatically added "OK" and "Cancel" come from GlassKit's resources.
  • Alerts cannot contain text fields or custom views through this type; use the system .alert directly for that.
  • The system decides the final visual order and emphasis of buttons on each platform; validation controls roles, presence and the order given to the system.
  • Attach .glassAlert once per binding. Validation is unit-tested; the presentation was compiled for iOS and macOS but not exercised in a running application by the automated tests.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassAlertExample: GlassExample {
    public static let componentID = "glass-alert"
    @State private var alert: GlassAlert?
    @State private var outcome = "Nothing chosen yet"

    public init() {}

    public var body: some View {
        VStack(spacing: 16) {
            GlassButton("Show information") {
                alert = GlassAlert(title: "Export finished", message: "The sample file was written to Documents.")
            }
            GlassButton("Unsaved changes…") {
                alert = GlassAlert(
                    title: "Save changes?",
                    message: "Your edits to “Budget 2027” will be lost otherwise.",
                    buttons: [
                        GlassAlertButton("Save") { outcome = "Saved" },
                        .destructive("Discard") { outcome = "Discarded" },
                        .cancel { outcome = "Cancelled" },
                    ]
                )
            }
            GlassButton("Delete draft…", systemImage: "trash", role: .destructive) {
                // No cancel button is given: validation adds one because the only action is destructive.
                alert = GlassAlert(
                    title: "Delete this draft?",
                    message: "This cannot be undone.",
                    style: .confirmation,
                    buttons: [.destructive("Delete draft") { outcome = "Deleted" }]
                )
            }
            Text(outcome).font(.callout).foregroundStyle(.secondary)
        }
        .padding()
        .glassAlert($alert)
    }
}

#Preview("GlassAlert") { GlassAlertExample() }

Registry entry

Identifierglass-alert
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassAlertButtonRole, GlassAlertButton, GlassAlertStyle, GlassAlert, GlassAlertValidator
LicenceMIT
Manifestmanifest.json

Files