Last active
August 15, 2019 13:09
-
-
Save wbbernardes/cb8cdc62136781ca48064c668c0c8235 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// Alert+ViewController.swift | |
// | |
// Created by Wesley Brito on 25/07/19. | |
// Copyright © 2019 Wesley Brito. All rights reserved. | |
// | |
import Foundation | |
extension UIViewController { | |
func showAlert(with title: String, | |
and subtitle: String? = nil, | |
with style: UIAlertController.Style, | |
withButtonsAndActions buttons: [(title: String, style: UIAlertAction.Style?, action: ((UIAlertAction) -> Void)?)]?) { | |
let alert = UIAlertController(title: title, | |
message: subtitle, | |
preferredStyle: style) | |
if let tuples = buttons { | |
for tuple in tuples { | |
alert.addAction(UIAlertAction(title: tuple.title, style: tuple.style ?? .default, handler: tuple.action)) | |
} | |
} | |
self.present(alert, animated: true, completion: nil) | |
} | |
func showSimpleAlert(title: String, message: String, action: ((UIAlertAction) -> Void)?) { | |
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) | |
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: action)) | |
self.present(alert, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment