Created
June 29, 2018 12:28
-
-
Save jonathanduty/7d555d5fdcf8de7d20e41b409f16d34f to your computer and use it in GitHub Desktop.
UIViewController+Extensions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
enum UIViewControllerDismissType { | |
case pop | |
case dismiss | |
} | |
extension UIViewController { | |
func presentAlertWithTitle(title: String = "Oops!", message: String, actions: [UIAlertAction] = [], preferredStyle: UIAlertControllerStyle = .alert, onComplete: ((KeystoneResultSimple) -> Void)? = nil) { | |
let alertController = UIAlertController(title: title, message: message, preferredStyle: preferredStyle) | |
if actions.isEmpty { | |
let alertAction = UIAlertAction(title: "OK", style: .default, handler: { (alert) in | |
onComplete?(.success) | |
}) | |
alertController.addAction(alertAction) | |
} | |
else { | |
actions.forEach({alertController.addAction($0)}) | |
} | |
present(alertController, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment