UIViewController

public extension UIViewController

A set of various extensions of the UIViewController class. These provide utilities for determining running state of the device, biometric support, and some responder stuff.

Class Computed Properties

  • Get the biometric authentication type.

    This is inspired by this SO answer

    Possible Values:

    • .none (no biometrics)
    • .touchID (Touch ID)
    • .faceID (Face ID)

    Declaration

    Swift

    class var biometricType: LABiometryType { get }
  • Returns true, if we are in High Contrast Mode.

    Declaration

    Swift

    class var isHighContrastMode: Bool { get }
  • Returns true, if we are in Reduced Transparency Mode.

    Declaration

    Swift

    class var isReducedTransparencyMode: Bool { get }
  • Returns true, if voiceover mode is on.

    Declaration

    Swift

    class var isVoiceOverRunning: Bool { get }
  • Returns true, if iCloud is available, and logged-in.

    NOTE: If iCloud is available, but the user is not logged in, this will also return false.

    Declaration

    Swift

    class var isICloudAvailable: Bool { get }
  • Returns the X/Y aspect of the screen (window).

    Declaration

    Swift

    class var screenAspect: CGFloat { get }

System State Flag Instance Computed Properties

  • Get the biometric authentication type.

    Possible Values:

    • .none (no biometrics)
    • .touchID (Touch ID)
    • .faceID (Face ID)

    Declaration

    Swift

    var biometricType: LABiometryType { get }
  • Returns true, if we are in High Contrast Mode.

    Declaration

    Swift

    var isHighContrastMode: Bool { get }
  • Returns true, if we are in Reduced Transparency Mode.

    Declaration

    Swift

    var isReducedTransparencyMode: Bool { get }
  • Returns true, if voiceover mode is on.

    Declaration

    Swift

    var isVoiceOverRunning: Bool { get }
  • Returns true, if iCloud is available, and logged-in.

    NOTE: If iCloud is available, but the user is not logged in, this will also return false.

    Declaration

    Swift

    var isICloudAvailable: Bool { get }

These are only available in instances

  • Returns true, if we are in Dark Mode.

    Declaration

    Swift

    var isDarkMode: Bool { get }
  • Returns true, if haptics are available.

    Declaration

    Swift

    var hapticsAreAvailable: Bool { get }

Device Instance Computed Properties

  • Returns the X/Y aspect of the screen (window).

    Declaration

    Swift

    var screenAspect: CGFloat { get }

View Hierarchy Instance Computed Properties

  • Returns the previous ViewController in a navigation stack. Nil, if at root, or not in a navigation stack. Inspired by this SO answer.

    Declaration

    Swift

    var previousViewController: UIViewController? { get }

Responder Stuff

  • This returns the first responder, wherever it is in our hierarchy.

    Declaration

    Swift

    var currentFirstResponder: UIResponder? { get }
  • This puts away any open keyboards. This is different from the UIView version, as it also forces endEditing(_:).

    Declaration

    Swift

    func resignAllFirstResponders()