Introspect

public enum Introspect

Utility methods to inspect the UIKit view hierarchy.

SwiftUI-Introspect

  • Finds a subview of the specified type. This method will recursively look for this view. Returns nil if it can’t find a view of the specified type.

    Declaration

    Swift

    public static func findChild<AnyViewType: UIView>(
        ofType type: AnyViewType.Type,
        in root: UIView
    ) -> AnyViewType?
  • Finds a child view controller of the specified type. This method will recursively look for this child. Returns nil if it can’t find a view of the specified type.

    Declaration

    Swift

    public static func findChild<AnyViewControllerType: UIViewController>(
        ofType type: AnyViewControllerType.Type,
        in root: UIViewController
    ) -> AnyViewControllerType?
  • Finds a subview of the specified type. This method will recursively look for this view. Returns nil if it can’t find a view of the specified type.

    Declaration

    Swift

    public static func findChildUsingFrame<AnyViewType: UIView>(
        ofType type: AnyViewType.Type,
        in root: UIView,
        from originalEntry: UIView
    ) -> AnyViewType?
  • Finds a previous sibling that contains a view of the specified type. This method inspects siblings recursively. Returns nil if no sibling contains the specified type.

    Declaration

    Swift

    public static func previousSibling<AnyViewType: UIView>(
        containing type: AnyViewType.Type,
        from entry: UIView
    ) -> AnyViewType?
  • Finds a previous sibling that is of the specified type. This method inspects siblings recursively. Returns nil if no sibling contains the specified type.

    Declaration

    Swift

    public static func previousSibling<AnyViewType: UIView>(
        ofType type: AnyViewType.Type,
        from entry: UIView
    ) -> AnyViewType?
  • Finds a previous sibling that contains a view controller of the specified type. This method inspects siblings recursively. Returns nil if no sibling contains the specified type.

    Declaration

    Swift

    @available(macOS, unavailable)
    public static func previousSibling<AnyViewControllerType: UIViewController>(
        containing type: AnyViewControllerType.Type,
        from entry: UIViewController
    ) -> AnyViewControllerType?
  • Finds a previous sibling that is a view controller of the specified type. This method does not inspect siblings recursively. Returns nil if no sibling is of the specified type.

    Declaration

    Swift

    public static func previousSibling<AnyViewControllerType: UIViewController>(
        ofType type: AnyViewControllerType.Type,
        from entry: UIViewController
    ) -> AnyViewControllerType?
  • Finds a next sibling that contains a view of the specified type. This method inspects siblings recursively. Returns nil if no sibling contains the specified type.

    Declaration

    Swift

    public static func nextSibling<AnyViewType: UIView>(
        containing type: AnyViewType.Type,
        from entry: UIView
    ) -> AnyViewType?
  • Finds a next sibling that if of the specified type. This method inspects siblings recursively. Returns nil if no sibling contains the specified type.

    Declaration

    Swift

    public static func nextSibling<AnyViewType: UIView>(
        ofType type: AnyViewType.Type,
        from entry: UIView
    ) -> AnyViewType?
  • Finds an ancestor of the specified type. If it reaches the top of the view without finding the specified view type, it returns nil.

    Declaration

    Swift

    public static func findAncestor<AnyViewType>(ofType type: AnyViewType.Type, from entry: UIView) -> AnyViewType? where AnyViewType : UIView
  • Finds an ancestor of the specified type. If it reaches the top of the view without finding the specified view type, it returns nil.

    Declaration

    Swift

    public static func findAncestorOrAncestorChild<AnyViewType>(ofType type: AnyViewType.Type, from entry: UIView) -> AnyViewType? where AnyViewType : UIView
  • Finds the hosting view of a specific subview. Hosting views generally contain subviews for one specific SwiftUI element. For instance, if there are multiple text fields in a VStack, the hosting view will contain those text fields (and their host views, see below). Returns nil if it couldn’t find a hosting view. This should never happen when called with an IntrospectionView.

    Declaration

    Swift

    public static func findHostingView(from entry: UIView) -> UIView?
  • Finds the view host of a specific view. SwiftUI wraps each UIView within a ViewHost, then within a HostingView. Returns nil if it couldn’t find a view host. This should never happen when called with an IntrospectionView.

    Declaration

    Swift

    public static func findViewHost(from entry: UIView) -> UIView?