UIAlertController

  • SwifterSwift: Present alert view controller in the current view controller.

    Declaration

    Swift

    public 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 public func addAction(title: String, style: UIAlertActionStyle = .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

    public 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

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

    Declaration

    Swift

    public 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

    public convenience init(title: String = "Error", error: Error, defaultActionButtonTitle: String = "OK", preferredStyle: UIAlertControllerStyle = .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)