Skip to content

Latest commit

 

History

History
51 lines (41 loc) · 1.14 KB

README.md

File metadata and controls

51 lines (41 loc) · 1.14 KB

Alert

Basic

struct ContentView: View {
    @State private var showingAlert = false

    var body: some View {
        Button("Show Alert") {
            showingAlert = true
        }
        .alert("Important message", isPresented: $showingAlert) {
            Button("Delete", role: .destructive) { }
            Button("Cancel", role: .cancel) { }
        }
    }
}

Message

struct ContentView: View {
    @State private var showingAlert = false
    @State var post: Post

    var body: some View {
        Button("Show Alert") {
            showingAlert = true
        }
        .alert("Delete this post?", isPresented: $showingAlert, presenting: post) { post in
            Button(role: .destructive) {
            } label: {
                Text("Delete")
            }
            Button("Cancel", role: .cancel) {}
        } message: { post in
            Text("Deleting this post will permanently remove \(post.title) from our server.")
        }
    }
}

Links that help