From 9ee1132d7d15474640a2e611edcfd439a30da64e Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Fri, 22 Jan 2021 14:54:00 -0500 Subject: [PATCH] [+] Encapsulate sending an alert --- ProjectClock/Utils.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ProjectClock/Utils.swift b/ProjectClock/Utils.swift index 4d5fdc8..28b9bd1 100644 --- a/ProjectClock/Utils.swift +++ b/ProjectClock/Utils.swift @@ -7,7 +7,9 @@ import Foundation import CryptoKit +import UIKit +/// Date manipulations extension Date { /// Add toString to Date @@ -79,6 +81,7 @@ extension TimeInterval } } + /// Apply like Kotlin protocol HasApply {} extension HasApply @@ -93,6 +96,7 @@ extension HasApply extension Alarm: HasApply {} extension Alarms: HasApply {} + /// Hashing extension Digest { @@ -104,3 +108,14 @@ extension String { var sha256: String { SHA256.hash(data: self.data(using: .utf8)!).b64 } } + + +/// Alerts +extension UIViewController +{ + func alert(_ title: String, _ message: String) + { + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + self.present(alert, animated: true, completion: nil) + } +}