iPhone SwiftUI layouts

Explore SwiftUI APIs, components, and modifiers with interactive iPhone previews, Swift code, and Apple documentation. Compare every available orientation, appearance, and design.

Alert

Error Alert

Presents an alert when an error is present.

Explore Error Alert on iPhone in portrait, with SwiftUI code and Apple API documentation.

enum FooError: LocalizedError {
    case bar

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

@State private var error: FooError? = .bar

var body: some View {
    Text("Foo")
        .alert(error: $error) {
            Button("OK") {
                print("Error nilled")
            }
        }
}
iOS 27.0+ iPadOS 27.0+ macOS 27.0+ watchOS 27.0+ tvOS 27.0+ visionOS 27.0+

Every available iPhone screenshot for Error Alert.

1 views