Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ class ViewController: UIViewController {

// MARK: Alert
@IBAction func showDefaultAlert(sender: UIButton) {
// UIAlertController.present(title: "title") { (action) -> () in
// UIAlertController.present(message: "message") { (action) -> () in
UIAlertController.present(title: "title", message: "message", actionTitles: ["OK", "Cancel", "Destroy"]) { (action) -> () in
print(action.title)
}
}


@IBAction func showAttributedAlert(sender: UIButton) {
UIAlertController.present(title: "title", message: "message", attributedActionTitles: [("OK", .Default), ("Cancel", .Cancel), ("Destroy", .Destructive)]) { (action) -> () in
print(action.title)
Expand Down
8 changes: 4 additions & 4 deletions Source/UIAlertControllerExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public typealias AttributedActionTitle = (title: String, style: UIAlertActionSty
public extension UIAlertController {

// Support Present UIAlertController from anywhere. It will be presented by Top Presented ViewController.
public class func present(style: UIAlertControllerStyle = .Alert, title: String?, message: String?, actionTitles: [String]?, handler: ActionHandler? = nil) -> UIAlertController {
public class func present(style: UIAlertControllerStyle = .Alert, title: String? = nil, message: String? = nil, actionTitles: [String]? = ["OK"], handler: ActionHandler? = nil) -> UIAlertController {
// Force unwrap rootViewController
let rootViewController = UIApplication.sharedApplication().delegate!.window!!.rootViewController!

return self.presentFromViewController(rootViewController, style: style, title: title, message: message, actionTitles: actionTitles, handler: handler)
}

public class func present(style: UIAlertControllerStyle = .Alert, title: String?, message: String?, attributedActionTitles: [AttributedActionTitle]?, handler: ActionHandler? = nil) -> UIAlertController {
public class func present(style: UIAlertControllerStyle = .Alert, title: String? = nil, message: String? = nil, attributedActionTitles: [AttributedActionTitle]?, handler: ActionHandler? = nil) -> UIAlertController {
// Force unwrap rootViewController
let rootViewController = UIApplication.sharedApplication().delegate!.window!!.rootViewController!

Expand Down Expand Up @@ -72,11 +72,11 @@ public extension UIAlertController {

// MARK:
public extension UIViewController {
public func presentAlert(style: UIAlertControllerStyle = .Alert, title: String?, message: String?, actionTitles: [String]?, handler: ActionHandler? = nil) -> UIAlertController {
public func presentAlert(style: UIAlertControllerStyle = .Alert, title: String? = nil, message: String? = nil, actionTitles: [String]? = ["OK"], handler: ActionHandler? = nil) -> UIAlertController {
return UIAlertController.presentFromViewController(self, style: style, title: title, message: message, actionTitles: actionTitles, handler: handler)
}

public func presentAlert(style: UIAlertControllerStyle = .Alert, title: String?, message: String?, attributedActionTitles: [AttributedActionTitle]?, handler: ActionHandler? = nil) -> UIAlertController {
public func presentAlert(style: UIAlertControllerStyle = .Alert, title: String? = nil, message: String? = nil, attributedActionTitles: [AttributedActionTitle]?, handler: ActionHandler? = nil) -> UIAlertController {
return UIAlertController.presentFromViewController(self, style: style, title: title, message: message, attributedActionTitles: attributedActionTitles, handler: handler)
}

Expand Down