VCBoss

public class VCBoss

Class used by a UIViewController to manage presenting and dismissing of UIViewControllers in a safe way. iOS throws errors if you try to call self.present() inside of a UIViewController when another UIViewController is already being shown. Replace all of your existing self.present() calls with using VCBoss and be safe knowing only 1 ViewController will be shown at a time.

Note: This class does not know about any UIViewControllers that you have already shown in it with self.present(). Make sure to place all existing self.present() calls with using VCBoss to assert you will not have any issues.

  • The UIViewController doing the presenting of other UIViewControllers modally or the UIViewController presented modally…or both.

    This is the UIViewController that was used in the instance(for:) constructor.

    Declaration

    Swift

    public weak var viewController: UIViewController?
  • Use to get instance of VCBoss for UIViewController. Internally, this class will get you a singleton of VCBoss for your UIViewController instance.

    Note: UIViewController used here is saved weak. Be sure to hold a reference to it until you no longer need it.

    Declaration

    Swift

    public class func instance(for: UIViewController) -> VCBoss
  • If you are interested to see how many UIViewControllers are in the stack of UIViewControllers to present modally.

    Declaration

    Swift

    public var numViewControllersPresenting: Int
  • Present this UIViewController now if no other UIViewController is presented, or show it in the future when it’s turn is next.

    @param force: Bool This param is used to say this UIViewController needs to be presented right now. Dismiss the UIViewController currently shown (if there is one), show this new UIViewController, then present the one I replaced again. Default: false

    Declaration

    Swift

    public func present(_ viewControllerToPresent: UIViewController, animated: Bool, completion: (() -> Void)?, force: Bool = false)
  • If another UIViewController is already being presented, ignore showing this one. Else, present it.

    Declaration

    Swift

    public func presentOnlyIfNothingAlreadyPresented(_ viewControllerToPresent: UIViewController, animated: Bool, completion: (() -> Void)?)
  • Take the currently shown UIViewController, dismiss it, and force show this new one immediately after.

    Declaration

    Swift

    public func replace(with viewController: UIViewController, animated: Bool, completion: (() -> Void)?)
  • Dismiss this UIViewController given. Then, present the next one in line if there is one.

    dismissCompletion and the completion handler given when this ViewController to dismiss was presented will both be called.

    If the viewController was never actually presented, an error will be thrown.

    Declaration

    Swift

    public func dismiss(_ viewController: UIViewController, animated: Bool, completion: (() -> Void)? = nil) throws
  • Dismiss the currently presented UIViewController and do not present anymore. Clear the stack to start over again.

    Declaration

    Swift

    public func dismissAll(animated: Bool, completion: (() -> Void)?) throws
  • Dismiss this UIViewController that was presented modally. This method internally calls .dismiss() on the presentingViewController’s VCBoss instance.

    This method exists to be backwards compatible with UIKit.

    Declaration

    Swift

    public func dismiss(animated: Bool, completion: (() -> Void)?) throws