From 58a7fe300c38a3b60d4a7bd50aaaae8e35475e8f Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 24 Jan 2021 19:31:44 -0500 Subject: [PATCH] [F] Fix alarm completion order --- ProjectClock/AccountViewController.swift | 3 +++ ProjectClock/Utils.swift | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ProjectClock/AccountViewController.swift b/ProjectClock/AccountViewController.swift index 16667e2..774c976 100644 --- a/ProjectClock/AccountViewController.swift +++ b/ProjectClock/AccountViewController.swift @@ -259,6 +259,9 @@ class FamilyCreateJoinVC: UIViewController sendReq(APIs.familyCreate, title: "Creating...", params: ["name": name, "pin": pin]) { self.msg("Created!", "Your family ID is \($0.fid)") + { + self.dismiss() + } } } } diff --git a/ProjectClock/Utils.swift b/ProjectClock/Utils.swift index f11d829..0d487ab 100644 --- a/ProjectClock/Utils.swift +++ b/ProjectClock/Utils.swift @@ -122,13 +122,13 @@ extension UIViewController - Parameter okayable: Whether the alert can be okayed */ @discardableResult - func alert(_ title: String, _ message: String, okayable: Bool = false) -> UIAlertController + func alert(_ title: String, _ message: String, okayable: Bool = false, _ completion: (() -> Void)? = nil) -> UIAlertController { // Create alert let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) // Add okay button if it's okayable - if okayable { alert.addAction(UIAlertAction(title: "OK", style: .default)) } + if okayable { alert.addAction(UIAlertAction(title: "OK", style: .default) { it in if let c = completion { c() } }) } // Display alert self.present(alert, animated: true, completion: nil) @@ -137,7 +137,10 @@ extension UIViewController /// A message is an okayable alert @discardableResult - func msg(_ title: String, _ message: String) -> UIAlertController { alert(title, message, okayable: true) } + func msg(_ title: String, _ message: String, _ completion: (() -> Void)? = nil) -> UIAlertController + { + alert(title, message, okayable: true, completion) + } /// More convenient dismiss function func dismiss(_ completion: (() -> Void)? = nil) { ui { self.dismiss(animated: false, completion: completion) } }