From f37a12c96397d93d2a182247f394bfc12c5102d7 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Fri, 22 Jan 2021 15:23:55 -0500 Subject: [PATCH] [O] Return the alert so that it can be dismissed programmatically --- ProjectClock/Utils.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ProjectClock/Utils.swift b/ProjectClock/Utils.swift index 894d4e9..1fab35a 100644 --- a/ProjectClock/Utils.swift +++ b/ProjectClock/Utils.swift @@ -120,17 +120,22 @@ extension UIViewController - Parameter message: Body message of the alert - Parameter okayable: Whether the alert can be okayed */ - func alert(_ title: String, _ message: String, okayable: Bool = false) + @discardableResult + func alert(_ title: String, _ message: String, okayable: Bool = false) -> UIAlertController { + // Create alert let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) - if okayable - { - alert.addAction(UIAlertAction(title: "OK", style: .default)) - } + // Add okay button if it's okayable + if okayable { alert.addAction(UIAlertAction(title: "OK", style: .default)) } + // Display alert self.present(alert, animated: true, completion: nil) + return alert } + + /// More convenient dismiss function + func dismiss() { dismiss(animated: false, completion: nil) } }