UIViewController

extension UIViewController
  • Instantiates a view controller from a storyboard.

    • Make sure all string literals are valid and have no typos; otherwise the method will throw a runtime exception.
    • If the view controller is named after the view controller subclass (e.g. MyViewController), you can omit viewControllerStoryboardID.

    Declaration

    Swift

    public static func instantiate(
        withStoryboardID viewControllerStoryboardID: String? = nil,
        fromStoryboardNamed storyboardName: String,
        in storyboardBundle: Bundle = .main
    ) -> Self

    Parameters

    viewControllerStoryboardID

    Optional. The storyboard ID of the view controller. You can view and set this ID in Interface Builder’s Identity inspector. Default is a string equal to the view controller subclass name (e.g. MyViewController).

    storyboardName

    Required. The name of the storyboard file.

    storyboardBundle

    Optional. The bundle the storyboard belongs to. Default is main.

Instantiation from Storyboards

  • Dismiss the current view controller.

    Declaration

    Swift

    @inline(__always)
    @objc
    public func dismissVC()

Alerts

  • Displays an alert with one or two options.

    • If primaryOptionLabelKey or primaryOptionAction is not set, the alert will have only one (cancel) option.

    Declaration

    Swift

    public func displayAlert(
        titled title: String,
        saying message: String? = nil,
        cancelOptionLabel: String = "OK",
        cancelOptionAction: ((UIAlertAction) -> Void)? = nil,
        primaryOptionLabel: String? = nil,
        primaryOptionStyle: UIAlertAction.Style = .default,
        primaryOptionAction: ((UIAlertAction) -> Void)? = nil
    )

    Parameters

    title

    Required. Title of the alert.

    message

    Optional. Message of the alert; default is nil.

    cancelOptionLabel

    Optional. Cancel option label; default is OK.

    cancelOptionAction

    Optional. Closure to execute when the cancel option is selected; default is nil.

    primaryOptionLabel

    Optional. Primary option label; default is nil.

    primaryOptionStyle

    Optional. See UIAlertAction.Style; default is default.

    primaryOptionAction

    Optional. Closure to execute when the primary option is selected; default is nil.

  • Displays an info alert with a single (OK) button.

    Declaration

    Swift

    public func displayInfoAlert(
        titled title: String,
        saying message: String? = nil,
        triggering postAlertAction: ((UIAlertAction) -> Void)? = nil
    )

    Parameters

    titleKey

    Required. Localization key for the title of the alert.

    messageKey

    Optional. Localization key for the message of the alert; default is nil.

    postAlertAction

    Optional. Closure to execute when the alert is dismissed; default is nil.

Localized Alerts

  • Displays an alert with one or two options with localized title, message, and option label keys.

    • If primaryOptionLabelKey or primaryOptionAction is not set, the alert will have only one (cancel) option.

    Declaration

    Swift

    public func displayLocalizedAlert(
        titled titleKey: String,
        saying messageKey: String? = nil,
        cancelOptionLabel cancelOptionLabelKey: String = "OK",
        cancelOptionAction: ((UIAlertAction) -> Void)? = nil,
        primaryOptionLabel primaryOptionLabelKey: String? = nil,
        primaryOptionStyle: UIAlertAction.Style = .default,
        primaryOptionAction: ((UIAlertAction) -> Void)? = nil
    )

    Parameters

    titleKey

    Required. Localization key for the title of the alert.

    messageKey

    Optional. Localization key for the message of the alert; default is nil.

    cancelOptionLabelKey

    Optional. Localization key for the cancel option label; default is OK (literally).

    cancelOptionAction

    Optional. Closure to execute when the cancel option is selected; default is nil.

    primaryOptionLabelKey

    Optional. Localization key for the primary option label; default is nil.

    primaryOptionStyle

    Optional. See UIAlertAction.Style; default is default.

    primaryOptionAction

    Optional. Closure to execute when the primary option is selected; default is nil.

  • Displays an info alert with a single (OK) button with localized title and message.

    Declaration

    Swift

    public func displayLocalizedInfoAlert(
        titled titleKey: String,
        saying messageKey: String? = nil,
        triggering postAlertAction: ((UIAlertAction) -> Void)? = nil
    )

    Parameters

    titleKey

    Required. Localization key for the title of the alert.

    messageKey

    Optional. Localization key for the message of the alert; default is nil.

    postAlertAction

    Optional. Closure to execute when the alert is dismissed; default is nil.