Alert in SwiftUI

Mar 21, 2022



image

Source code :

// ContentView.swift

// AlertDialog

//

// Created by Saveta Mobile Academy on 01.03.21.

//

import SwiftUI

struct ContentView: View {

@State private var showingAlert = false

var body: some View {

VStack{

Button("Show Alert") {

showingAlert = true

}

}.alert(isPresented: $showingAlert) {

Alert(title: Text("Alert message"), message: Text("Are you sure?"), primaryButton: .default(Text("Confirm"), action: {

// your action here

}),

secondaryButton: .default(Text("Cancel")))

}

}

}

struct ContentView_Previews: PreviewProvider {

static var previews: some View {

ContentView()

}

}

Enjoy this post?

Buy Saveta Mobile Academy a coffee

More from Saveta Mobile Academy