Skip to content

Instantly share code, notes, and snippets.

@wbbernardes
Last active August 15, 2019 13:09
Show Gist options
  • Save wbbernardes/cb8cdc62136781ca48064c668c0c8235 to your computer and use it in GitHub Desktop.
Save wbbernardes/cb8cdc62136781ca48064c668c0c8235 to your computer and use it in GitHub Desktop.
//
// 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