-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlertController.swift
More file actions
35 lines (31 loc) · 1.38 KB
/
Copy pathAlertController.swift
File metadata and controls
35 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import UIKit
extension UIViewController {
/// Show an alert with a title, message, and OK button
/// - Parameters:
/// - title: The Alert's Title
/// - message: The Alert's Message
func presentAlert(title: String, message: String, completion: @escaping (UIAlertAction) -> Void = {_ in }) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: completion))
DispatchQueue.main.async {
self.present(alert, animated: true)
}
}
/// Show an alert with a title, message, yes button, and no button
/// - Parameters:
/// - title: The Alert's Title
/// - message: The Alert's Message
/// - complete: Returns a bool (false if no was pressed, true if yes)
func presentAlertwithYesNoPrompt(title: String, message: String, complete: @escaping (Bool) -> Void) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { _ in
complete(true)
}))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: { _ in
complete(false)
}))
DispatchQueue.main.async {
self.present(alert, animated: true)
}
}
}