[Swift 4] AlertAction File

I have a sheet file Alert Action to call. example like this below

struct AlertACT {
    // .Alert
    static func showBasicAlert(on vc: UIViewController, with title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        vc.present(alert, animated: true)
    }

And this full file :

import Foundation
import UIKit

struct AlertACT {
    // .Alert
    static func showBasicAlert(on vc: UIViewController, with title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
        vc.present(alert, animated: true)
    }
 
    static func backAlert(on vc: UIViewController, with title: String, message: String) {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
            vc.navigationController?.popViewController(animated: true)
        }))
        vc.present(alert, animated: true)
    }
 
    // .ActionSheet
 
    static func showActionSheet(on vc: UIViewController, vc1: UIViewController, vc2: UIViewController, vc3: UIViewController) {
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        alert.view.tintColor = #colorLiteral(red: 0.6642242074, green: 0.6642400622, blue: 0.6642315388, alpha: 1)
     
        alert.addAction(UIAlertAction(title: "Menu 1", style: .default, handler: { _ in
            vc.navigationController?.pushViewController(vc1, animated: false)
        }))
        alert.addAction(UIAlertAction(title: "Menu 2", style: .default, handler: { _ in
            vc.navigationController?.pushViewController(vc2, animated: false)
        }))
        alert.addAction(UIAlertAction(title: "Menu 3", style: .default, handler: { _ in
            vc.navigationController?.pushViewController(vc3, animated: false)
        }))
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        vc.present(alert, animated: true)
    }
 
 
    static func fieldEmpty(on vc: UIViewController) {
        showBasicAlert(on: vc, with: "Message", message: "password minimal 6 character")
    }
 
 
}

or can download this file for 30 day -> https://www90.zippyshare.com/v/DrQFeHz4/file.html


Buy me a coffeeBuy me a coffee

No comments: