Error Alert
Presents an alert when an error is present.
Platform Compatibility
Tags
SwiftUI Code
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")
}
}
}Found an issue or have a suggestion?
More Alert Components
View allMessage 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.
Explore Other Components
Browse allLinearGaugeStyle
A gauge style that displays a bar with a marker that appears at a point along the bar to indicate the gauge’s current value
Value Tab View
Creates a tab view that uses a builder to create and specify selection values for its tabs.
Overlay Arrangement Style
An arrangement view style that layers the primary view over the secondary view in z-order.
Default Adaptable Tab Bar Placement
Specifies the default placement for the tabs in a tab view using the adaptable sidebar style.
Custom Phases Async URL Image
Loads and displays a modifiable image from the specified URL load request in phases.
CompactProductViewStyle
A style for a product view that’s suitable for layouts with less available space, or for displaying more items in a small amount of space.