Instance Method インスタンスメソッド

alert(isPresented:content:)

Presents an alert to the user. アラートをユーザに提示します。

Declaration 宣言

func alert(isPresented: Binding<Bool>, content: () -> Alert) -> some View

Parameters パラメータ

isPresented

A binding to a Boolean value that determines whether to present the alert that you create in the modifier’s content closure. When the user presses or taps OK the system sets isPresented to false which dismisses the alert.

content

A closure returning the alert to present. 提示するアラートを返しているあるクロージャ。

Discussion 議論

Use this method when you need to show an alert to the user. The example below displays an alert that is shown when the user toggles a Boolean value that controls the presentation of the alert:


struct OrderCompleteAlert: View {
    @State private var isPresented = false
    var body: some View {
        Button("Show Alert", action: {
            isPresented = true
        })
        .alert(isPresented: $isPresented) {
            Alert(title: Text("Order Complete"),
                  message: Text("Thank you for shopping with us."),
                  dismissButton: .default(Text("OK")))
        }
    }
}

An alert whose title reads Order Complete, with the