Interactive previews iPhone

Message Error Alert

Presents an alert with a message when an error is present.

Message Error Alert - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview

Platform Compatibility

iOS 27.0+ iPadOS 27.0+ macOS 27.0+ watchOS 27.0+ tvOS 27.0+ visionOS 27.0+

Tags

SwiftUI Code

Docs
enum FooError: LocalizedError {
    case bar

    var errorDescription: String? {
        switch self {
            case .bar:
            return "Bar error occurred."
        }
    }

    var message: String {
        switch self {
            case .bar:
            return "This is a message for the Bar error."
        }
    }
}

@State private var error: FooError? = .bar

var body: some View {
    Text("Foo")
        .alert(error: $error) { errorItem in
            Button("OK") {
                print("\(errorItem) nilled")
            }
        } message: { errorItem in
            Text(errorItem.message)
        }
}

Found an issue or have a suggestion?

Created: June 9, 2026Updated: June 9, 2026

More Alert Components

View all
Message Item Alert - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
modifier

Message Item Alert

Presents an alert with a message using the given data to produce the alert’s content and a localized string key for a title.

Item Alert - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
modifier

Item Alert

Presents an alert using the given data to produce the alert’s content and a text view as a title.

Error Alert - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
modifier

Error Alert

Presents an alert when an error is present.

Explore Other Components

Browse all
Container Content Margins - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
modifier

Container Content Margins

Adds the margins of the container the view is in.

Custom Icon Store View - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
initializer

Custom Icon Store View

Creates a view to load a collection of products from the App Store using product identifiers, and merchandise them using a custom image.

Collapse Sidebar Sections by Default - iPadOS - Landscape - Liquid Glass - Light Mode - Preview
modifier

Collapse Sidebar Sections by Default

Collapses the section in the sidebar by default.

RegularProductViewStyle - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
style

RegularProductViewStyle

A style for a product view that uses a standard, platform-appropriate layout.

Color Variants - iOS on iPhone - Portrait - Flat Design - Light Mode - Preview
modifier

Color Variants

HierarchicalShapeStyle, a shape style that maps to one of the numbered content styles

Image Label - iOS on iPhone - Portrait - Liquid Glass - Light Mode - Preview
initializer

Image Label

Creates a label with an icon image and a title generated from a localized string.

Sheet Placement - iOS on iPhone Duo - Landscape - Fully Open - Liquid Glass - Light Mode - Preview
modifier

Sheet Placement

Sets the placement of a presentation within the presenting view. This may fall back to center on small screens.

VerticalPageTabViewStyle - watchOS - Liquid Glass - Light Mode - Preview
style

VerticalPageTabViewStyle

A TabViewStyle that displays a vertical TabView interaction and appearance.