diff --git a/Sources/IntrospectionSelector.swift b/Sources/IntrospectionSelector.swift index 14d2ecc..ea691aa 100644 --- a/Sources/IntrospectionSelector.swift +++ b/Sources/IntrospectionSelector.swift @@ -1,12 +1,30 @@ @_spi(Internals) public struct IntrospectionSelector { - private let selector: (any PlatformEntity, IntrospectionScope, IntrospectionAnchorID) -> Target? + private let selector: (IntrospectionPlatformViewController, IntrospectionScope, IntrospectionAnchorID) -> Target? static var `default`: Self { .from(Target.self, selector: { $0 }) } @_spi(Internals) public static func from(_ entryType: Entry.Type, selector: @escaping (Entry) -> Target?) -> Self { - .init { entity, scope, anchorID in + .init { controller, scope, anchorID in + guard let entity = { () -> (any PlatformEntity)? in + if Entry.Base.self == PlatformView.self { + #if canImport(UIKit) + if let introspectionView = controller.viewIfLoaded { + return introspectionView + } + #elseif canImport(AppKit) + if controller.isViewLoaded { + return controller.view + } + #endif + } else if Entry.Base.self == PlatformViewController.self { + return controller + } + return nil + }() else { + return nil + } if scope.contains(.receiver), let entry = entity.receiver(ofType: Entry.self, anchorID: anchorID), @@ -25,15 +43,15 @@ public struct IntrospectionSelector { } } - init(_ selector: @escaping (any PlatformEntity, IntrospectionScope, IntrospectionAnchorID) -> Target?) { + init(_ selector: @escaping (IntrospectionPlatformViewController, IntrospectionScope, IntrospectionAnchorID) -> Target?) { self.selector = selector } func callAsFunction( - _ entity: any PlatformEntity, + _ controller: IntrospectionPlatformViewController, _ scope: IntrospectionScope, _ anchorID: IntrospectionAnchorID ) -> Target? { - selector(entity, scope, anchorID) + selector(controller, scope, anchorID) } } diff --git a/Sources/IntrospectionView.swift b/Sources/IntrospectionView.swift index 28cacba..0965098 100644 --- a/Sources/IntrospectionView.swift +++ b/Sources/IntrospectionView.swift @@ -81,26 +81,11 @@ struct IntrospectionView: PlatformViewControllerRepresen private let customize: (Target) -> Void init( - selector: @escaping (any PlatformEntity) -> Target?, + selector: @escaping (IntrospectionPlatformViewController) -> Target?, customize: @escaping (Target) -> Void ) { self._observed = .constant(()) - self.selector = { introspectionController in - if Target.Base.self == PlatformView.self { - #if canImport(UIKit) - if let introspectionView = introspectionController.viewIfLoaded { - return selector(introspectionView) - } - #elseif canImport(AppKit) - if introspectionController.isViewLoaded { - return selector(introspectionController.view) - } - #endif - } else if Target.Base.self == PlatformViewController.self { - return selector(introspectionController) - } - return nil - } + self.selector = selector self.customize = customize }