UIViewController

class UIViewController : UIResponder, NSCoding, UIAppearanceContainer, UITraitEnvironment, UIContentContainer, UIFocusEnvironment
  • SwifterSwift: Check if ViewController is onscreen and not hidden.

    Declaration

    Swift

    var isVisible: Bool { get }
  • SwifterSwift: Assign as listener to notification.

    Declaration

    Swift

    func addNotificationObserver(name: Notification.Name, selector: Selector)

    Parameters

    name

    notification name.

    selector

    selector to run with notified.

  • SwifterSwift: Unassign as listener to notification.

    Declaration

    Swift

    func removeNotificationObserver(name: Notification.Name)

    Parameters

    name

    notification name.

  • SwifterSwift: Unassign as listener from all notifications.

    Declaration

    Swift

    func removeNotificationsObserver()
  • SwifterSwift: Helper method to display an alert on any UIViewController subclass. Uses UIAlertController to show an alert

    Declaration

    Swift

    @discardableResult
    func showAlert(title: String?, message: String?, buttonTitles: [String]? = nil, highlightedButtonIndex: Int? = nil, completion: ((Int) -> Void)? = nil) -> UIAlertController

    Parameters

    title

    title of the alert

    message

    message/body of the alert

    buttonTitles

    (Optional)list of button titles for the alert. Default button i.e OK will be shown if this paramter is nil

    highlightedButtonIndex

    (Optional) index of the button from buttonTitles that should be highlighted. If this parameter is nil no button will be highlighted

    completion

    (Optional) completion block to be invoked when any one of the buttons is tapped. It passes the index of the tapped button as an argument

    Return Value

    UIAlertController object (discardable).

  • SwifterSwift: Helper method to add a UIViewController as a childViewController.

    Declaration

    Swift

    func addChildViewController(_ child: UIViewController, toContainerView containerView: UIView)

    Parameters

    child

    the view controller to add as a child

    containerView

    the containerView for the child viewcontroller’s root view.

  • SwifterSwift: Helper method to remove a UIViewController from its parent.

    Declaration

    Swift

    func removeViewAndControllerFromParentViewController()
  • SwifterSwift: Helper method to present a UIViewController as a popover.

    Declaration

    Swift

    func presentPopover(_ popoverContent: UIViewController, sourcePoint: CGPoint, size: CGSize? = nil, delegate: UIPopoverPresentationControllerDelegate? = nil, animated: Bool = true, completion: (() -> Void)? = nil)

    Parameters

    popoverContent

    the view controller to add as a popover.

    sourcePoint

    the point in which to anchor the popover.

    size

    the size of the popover. Default uses the popover preferredContentSize.

    delegate

    the popover’s presentationController delegate. Default is nil.

    animated

    Pass true to animate the presentation; otherwise, pass false.

    completion

    The block to execute after the presentation finishes. Default is nil.