UIAlertController

public extension UIAlertController
  • SwifterSwift: Present alert view controller in the current view controller.

    Declaration

    Swift

    func show(animated: Bool = true, vibrate: Bool = false, completion: (() -> Void)? = nil)

    Parameters

    animated

    set true to animate presentation of alert controller (default is true).

    vibrate

    set true to vibrate the device while presenting the alert (default is false).

    completion

    an optional completion handler to be called after presenting alert controller (default is nil).

  • SwifterSwift: Add an action to Alert

    Declaration

    Swift

    @discardableResult
    func addAction(title: String, style: UIAlertAction.Style = .default, isEnabled: Bool = true, handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertAction

    Parameters

    title

    action title

    style

    action style (default is UIAlertActionStyle.default)

    isEnabled

    isEnabled status for action (default is true)

    handler

    optional action handler to be called when button is tapped (default is nil)

    Return Value

    action created by this method

  • SwifterSwift: Add a text field to Alert

    Declaration

    Swift

    func addTextField(text: String? = nil, placeholder: String? = nil, editingChangedTarget: Any?, editingChangedSelector: Selector?)

    Parameters

    text

    text field text (default is nil)

    placeholder

    text field placeholder text (default is nil)

    editingChangedTarget

    an optional target for text field’s editingChanged

    editingChangedSelector

    an optional selector for text field’s editingChanged

Initializers

  • SwifterSwift: Create new alert view controller with default OK action.

    Declaration

    Swift

    convenience init(title: String, message: String? = nil, defaultActionButtonTitle: String = "OK", tintColor: UIColor? = nil)

    Parameters

    title

    alert controller’s title.

    message

    alert controller’s message (default is nil).

    defaultActionButtonTitle

    default action button title (default is “OK”)

    tintColor

    alert controller’s tint color (default is nil)

  • SwifterSwift: Create new error alert view controller from Error with default OK action.

    Declaration

    Swift

    convenience init(title: String = "Error", error: Error, defaultActionButtonTitle: String = "OK", preferredStyle: UIAlertController.Style = .alert, tintColor: UIColor? = nil)

    Parameters

    title

    alert controller’s title (default is “Error”).

    error

    error to set alert controller’s message to it’s localizedDescription.

    defaultActionButtonTitle

    default action button title (default is “OK”)

    tintColor

    alert controller’s tint color (default is nil)