UIKitIntrospectionView

@available(iOS 13.0, tvOS 13.0, macOS 10.15.0, *)
public struct UIKitIntrospectionView<TargetViewType> : UIViewRepresentable where TargetViewType : UIView

Introspection View that is injected into the UIKit hierarchy alongside the target view. After updateUIView is called, it calls selector to find the target view, then customize when the target view is found.

  • Undocumented

    Declaration

    Swift

    public init(
        selector: @escaping (IntrospectionUIView) -> TargetViewType?,
        customize: @escaping (TargetViewType) -> Void
    )
  • Declaration

    Swift

    public func makeUIView(context: UIViewRepresentableContext<UIKitIntrospectionView>) -> IntrospectionUIView
  • When updateUiView is called after creating the Introspection view, it is not yet in the UIKit hierarchy. At this point, introspectionView.superview.superview is nil and we can’t access the target UIKit view. To workaround this, we wait until the runloop is done inserting the introspection view in the hierarchy, then run the selector. Finding the target view fails silently if the selector yield no result. This happens when updateUIView gets called when the introspection view gets removed from the hierarchy.

    Declaration

    Swift

    public func updateUIView(
        _ uiView: IntrospectionUIView,
        context: UIViewRepresentableContext<UIKitIntrospectionView>
    )