Skip to content

Instantly share code, notes, and snippets.

@Jamonek
Created December 10, 2015 10:27
Show Gist options
  • Save Jamonek/b01938e556f4ab4a6acf to your computer and use it in GitHub Desktop.
Save Jamonek/b01938e556f4ab4a6acf to your computer and use it in GitHub Desktop.
import UIKit
extension UIViewController {
func alert(title: String = "", message: String, actionTitle:String = "OK") {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let OKAction = UIAlertAction(title: actionTitle, style: .Default, handler: nil)
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
// Example Usage
class TestVC: UIViewController {
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.alert("Hello", message: "This is a sample alert controller", actionTitle: "Dismiss")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment