From 3d28a95b893ee95a42d63e0cc82f997d88b9c995 Mon Sep 17 00:00:00 2001 From: Jungpyo Hong <54448459+jphong1111@users.noreply.github.com> Date: Wed, 5 May 2021 12:26:52 -0500 Subject: [PATCH] Create AlertProtocol.swift --- Helper/AlertProtocol/AlertProtocol.swift | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Helper/AlertProtocol/AlertProtocol.swift diff --git a/Helper/AlertProtocol/AlertProtocol.swift b/Helper/AlertProtocol/AlertProtocol.swift new file mode 100644 index 0000000..a28ce20 --- /dev/null +++ b/Helper/AlertProtocol/AlertProtocol.swift @@ -0,0 +1,44 @@ +// +// AlertProtocol.swift +// VariousManagerDemoApp +// +// Created by JungpyoHong on 4/21/21. +// +import UIKit + +enum AlertButton: String { + case ok + case cancel + case delete + case settings +} + +protocol AlertProtocol: UIViewController { + func showAlert(title: String, message: String, buttons: [AlertButton], completion: @escaping (UIAlertController, AlertButton) -> Void) +} + +extension AlertProtocol { + + func showAlert(title: String, message: String, buttons: [AlertButton] = [.ok], completion: @escaping (UIAlertController, AlertButton) -> Void) { + + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + + buttons.forEach { button in + let action = UIAlertAction(title: button.rawValue.capitalized, style: button == .delete ? .destructive : .default) { [alert, button] _ in + completion(alert, button) + } + alert.addAction(action) + } + self.present(alert, animated: true, completion: nil) + } +} + +protocol CellReusable { + static var identifier: String { get } +} + +extension CellReusable { + static var identifier: String { + String(describing: self) + } +}