Alert Demo

//
//  ViewController.swift
//  AlertPractice

import UIKit

class ViewController: UIViewController{

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func saveButton(_ sender: UIButton) {
        
        let alert = UIAlertController(title: "SAVE", message:"Do You Want TO SAVE?", preferredStyle: .alert)
        
        let yesAlert = UIAlertAction(title: "YES", style: .default)
        {
            (action) in
            print("yes")
            
        }
        
        let noAlert = UIAlertAction(title: "NO", style: .cancel)
        {
            (action) in
            print("NO")
        }
        
        alert.addAction(yesAlert)
        alert.addAction(noAlert)
        
        self.present(alert, animated: true, completion: nil)
        
        
        
        
        
        
    }

    @IBAction func deleteButton(_ sender: UIButton) {
        
        let alertAction = UIAlertController(title: "DELETE", message: "Do You Want TO DELETE", preferredStyle: .actionSheet)
        
        let yesAlertAction = UIAlertAction(title: "YES", style: .default)
        {
            (action) in
            print("yes")
            
        }
        
        let noAlertAction = UIAlertAction(title: "NO", style: .cancel)
        {
            (action) in
            print("no")
        }
            alertAction.addAction(yesAlertAction)
            alertAction.addAction(noAlertAction)
            
            self.present(alertAction, animated: true, completion: nil)
        
        
    }

}

Comments