create alert in swift
class ViewController: UIViewController { @IBAction func showAlertButtonTapped(_ sender: UIButton) { // create the alert let alert = UIAlertController(title: "My Title", message: "This is my message.", preferredStyle: .alert) // add an action (button) alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil)) // show the alert self.present(alert, animated: true, completion: nil) } }
Source: stackoverflow.com
simple alert swifti
struct ContentView: View { @State private var showingAlert = false var body: some View { Button("Show Alert") { showingAlert = true } .alert("Important message", isPresented: $showingAlert) { Button("OK", role: .cancel) { } } } }
Source: www.hackingwithswift.com