// // UIViewController+Extensions.swift // Notes // // Created by Laurent Morvillier on 19/09/2022. // import Foundation import UIKit extension UIViewController { @objc public func showAlert(message: String, title: String?, completion: (() -> ())? = nil) { let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) let action = UIAlertAction(title: NSLocalizedString("OK", comment: "OK"), style: .default, handler: nil) alertController.addAction(action) self.present(alertController, animated: true, completion: completion) } func areYouSure(title: String? = nil, message: String? = NSLocalizedString("Please confirm the action", comment: ""), executable: @escaping () -> Void) { let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(UIAlertAction(title: NSLocalizedString("No", comment:""), style: .cancel, handler: { _ in // do nothing })) alert.addAction(UIAlertAction(title: NSLocalizedString("Yes", comment:""), style: .destructive, handler: { action in executable() })) self.present(alert, animated: true, completion: nil) } }