From 3fd2795a48a50938b5c4127888e5a0da299b646b Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Tue, 23 Jul 2024 00:48:32 +0200 Subject: [PATCH 1/4] Fix lint errors --- Package.swift | 4 +- Sources/Inspect/Inspect.swift | 70 +++++++++++++++++------------------ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Package.swift b/Package.swift index 28b0fa2..3ad7ee5 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,7 @@ let package = Package( // Products define the executables and libraries a package produces, making them visible to other packages. .library( name: "Inspect", - targets: ["Inspect"]), + targets: ["Inspect"]) ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -24,6 +24,6 @@ let package = Package( name: "Inspect"), .testTarget( name: "InspectTests", - dependencies: ["Inspect"]), + dependencies: ["Inspect"]) ] ) diff --git a/Sources/Inspect/Inspect.swift b/Sources/Inspect/Inspect.swift index 4e3c7b0..4026e25 100644 --- a/Sources/Inspect/Inspect.swift +++ b/Sources/Inspect/Inspect.swift @@ -21,16 +21,16 @@ public typealias PlatformControl = NSControl public typealias PlatformViewRepresentable = NSViewRepresentable public typealias PlatformViewRepresentableContext = NSViewRepresentableContext public typealias PlatformViewController = NSViewController -public typealias PlatformViewControllerRepresentable = NSViewControllerRepresentable -public typealias PlatformViewControllerRepresentableContext = NSViewControllerRepresentableContext +public typealias PlatformVCRepresentable = NSViewControllerRepresentable +public typealias PlatformVCRepresentableContext = NSViewControllerRepresentableContext #else public typealias PlatformView = UIView public typealias PlatformControl = UIControl public typealias PlatformViewRepresentable = UIViewRepresentable public typealias PlatformViewRepresentableContext = UIViewRepresentableContext public typealias PlatformViewController = UIViewController -public typealias PlatformViewControllerRepresentable = UIViewControllerRepresentable -public typealias PlatformViewControllerRepresentableContext = UIViewControllerRepresentableContext +public typealias PlatformVCRepresentable = UIViewControllerRepresentable +public typealias PlatformVCRepresentableContext = UIViewControllerRepresentableContext #endif // MARK: - Inspector @@ -47,13 +47,13 @@ public enum Inspector { /// - root: Root view /// /// - Returns: The view of type (if found) - public static func findChild( - ofType type: viewOfType.Type, + public static func findChild( + ofType type: ViewOfType.Type, in root: PlatformView - ) -> viewOfType? { + ) -> ViewOfType? { // Search in subviews for subview in root.subviews { - if let searchedView = subview as? viewOfType { + if let searchedView = subview as? ViewOfType { return searchedView } else if let searchedView = findChild(ofType: type, in: subview) { return searchedView @@ -75,10 +75,10 @@ public enum Inspector { /// - from: From View /// /// - Returns: The view of type (if found) - public static func firstSibling( - ofType type: viewOfType.Type, + public static func firstSibling( + ofType type: ViewOfType.Type, from entry: PlatformView - ) -> viewOfType? { + ) -> ViewOfType? { // Check if we can find a superview, and a subview with an index of PlatformView guard let superview = entry.superview, let entryIndex = superview.subviews.firstIndex(of: entry) else { @@ -109,17 +109,17 @@ public enum Inspector { /// - from: From view /// /// - Returns: The view of type (if found) - public static func findAncestor( - ofType type: viewOfType.Type, + public static func findAncestor( + ofType type: ViewOfType.Type, from entry: PlatformView - ) -> viewOfType? { + ) -> ViewOfType? { // Get the view above the current view (superview) var superview = entry.superview // Walk trough the subviews while let currentView = superview { // Is the current view the type we search for? - if let searchedView = currentView as? viewOfType { + if let searchedView = currentView as? ViewOfType { // We found the view. return searchedView } @@ -143,17 +143,17 @@ public enum Inspector { /// - from: From View /// /// - Returns: The view of type (if found) - public static func find( - ofType type: viewOfType.Type, + public static func find( + ofType type: ViewOfType.Type, from entry: PlatformView - ) -> viewOfType? { + ) -> ViewOfType? { // Get the view above the current view (superview) var superview = entry.superview // Walk trough the subviews while let currentView = superview { // Is the current view the type we search for? - if let searchedView = currentView as? viewOfType { + if let searchedView = currentView as? ViewOfType { // We found the view. return searchedView } @@ -165,8 +165,7 @@ public enum Inspector { // Search previous sibling if let superview = entry.superview, let entryIndex = superview.subviews.firstIndex(of: entry), - entryIndex > 0 - { + entryIndex > 0 { for subview in superview.subviews[0.. NSView? { + override public func hitTest(_ point: NSPoint) -> NSView? { return nil } #endif @@ -366,12 +365,12 @@ public class InspectPlatformViewController: PlatformViewController { // MARK: Inspect (View Controller) /// Inspect a PlatformViewController -public struct InspectVC: PlatformViewControllerRepresentable { +public struct InspectVC: PlatformVCRepresentable { /// The selector we want to use - let selector: (InspectPlatformViewController) -> TargetViewControllerType? + let selector: (InspectPlatformViewController) -> TargetVCType? /// User-provided customization method for the target view. - let customizer: (TargetViewControllerType) -> Void + let customizer: (TargetVCType) -> Void /// Inspect a PlatformViewController. /// @@ -389,8 +388,8 @@ public struct InspectVC: Platf /// - Parameter selector: Selector to use /// - Parameter customizer: Customizer public init( - _ selector: @escaping (PlatformViewController) -> TargetViewControllerType?, - customizer: @escaping (TargetViewControllerType) -> Void + _ selector: @escaping (PlatformViewController) -> TargetVCType?, + customizer: @escaping (TargetVCType) -> Void ) { self.selector = selector self.customizer = customizer @@ -400,7 +399,7 @@ public struct InspectVC: Platf public func makeNSViewController(context: Context) -> InspectPlatformViewController { let viewController = InspectPlatformViewController() #if os(macOS) - viewController.view.setAccessibilityLabel("InspectVC<\(TargetViewControllerType.self)>") + viewController.view.setAccessibilityLabel("InspectVC<\(TargetVCType.self)>") #endif return viewController } @@ -416,18 +415,18 @@ public struct InspectVC: Platf // MARK: UIKit public func makeUIViewController( - context: PlatformViewControllerRepresentableContext + context: PlatformVCRepresentableContext ) -> InspectPlatformViewController { let viewController = InspectPlatformViewController() #if !os(macOS) - viewController.view.accessibilityLabel = "InspectVC<\(TargetViewControllerType.self)>" + viewController.view.accessibilityLabel = "InspectVC<\(TargetVCType.self)>" #endif return viewController } public func updateUIViewController( _ uiViewController: InspectPlatformViewController, - context: PlatformViewControllerRepresentableContext + context: PlatformVCRepresentableContext ) { DispatchQueue.main.asyncAfter(deadline: .now()) { guard let targetView = self.selector(uiViewController) else { @@ -441,7 +440,7 @@ public struct InspectVC: Platf extension View { public func inspect( _ element: TargetView.Type, - customizer: @escaping (TargetView) -> () + customizer: @escaping (TargetView) -> Void ) -> some View { return overlay( Inspect( @@ -456,7 +455,7 @@ extension View { public func inspect( viewControllerSelector: @escaping (PlatformViewController) -> TargetView?, - customizer: @escaping (PlatformViewController) -> () + customizer: @escaping (PlatformViewController) -> Void ) -> some View { return overlay( InspectVC( @@ -470,4 +469,5 @@ extension View { } } -#endif \ No newline at end of file +#endif +// swiftlint:disable:this file_length From b16a2f374b9d77cd4671be2cec90aa89c8a5b4a0 Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Tue, 23 Jul 2024 00:52:35 +0200 Subject: [PATCH 2/4] Fix lint errors --- Sources/Inspect/Inspect.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/Inspect/Inspect.swift b/Sources/Inspect/Inspect.swift index 4026e25..764c01e 100644 --- a/Sources/Inspect/Inspect.swift +++ b/Sources/Inspect/Inspect.swift @@ -16,16 +16,16 @@ import SwiftUI // MARK: - Platform Definitions #if os(macOS) +/// Current platform's view type public typealias PlatformView = NSView -public typealias PlatformControl = NSControl public typealias PlatformViewRepresentable = NSViewRepresentable public typealias PlatformViewRepresentableContext = NSViewRepresentableContext public typealias PlatformViewController = NSViewController public typealias PlatformVCRepresentable = NSViewControllerRepresentable public typealias PlatformVCRepresentableContext = NSViewControllerRepresentableContext #else +/// Current platform's view type public typealias PlatformView = UIView -public typealias PlatformControl = UIControl public typealias PlatformViewRepresentable = UIViewRepresentable public typealias PlatformViewRepresentableContext = UIViewRepresentableContext public typealias PlatformViewController = UIViewController @@ -438,6 +438,10 @@ public struct InspectVC: PlatformVCReprese } extension View { + /// Inspect + /// + /// - Parameter element: Element to inspect + /// - Parameter customizer: Element to modify public func inspect( _ element: TargetView.Type, customizer: @escaping (TargetView) -> Void @@ -453,6 +457,10 @@ extension View { ) } + /// Inspect View Controller + /// + /// - Parameter viewControllerSelector: View controller selector + /// - Parameter customizer: Element to modify public func inspect( viewControllerSelector: @escaping (PlatformViewController) -> TargetView?, customizer: @escaping (PlatformViewController) -> Void From fa7d609074fdf4c54b71408f91dc0a011107ca0f Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Tue, 23 Jul 2024 10:23:51 +0200 Subject: [PATCH 3/4] Fix lint errors --- Sources/Inspect/Inspect.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sources/Inspect/Inspect.swift b/Sources/Inspect/Inspect.swift index 764c01e..a85832f 100644 --- a/Sources/Inspect/Inspect.swift +++ b/Sources/Inspect/Inspect.swift @@ -16,20 +16,30 @@ import SwiftUI // MARK: - Platform Definitions #if os(macOS) -/// Current platform's view type +/// Current platform's view public typealias PlatformView = NSView +/// Current platform's view representable public typealias PlatformViewRepresentable = NSViewRepresentable +/// Current platform's view representable context public typealias PlatformViewRepresentableContext = NSViewRepresentableContext +/// Current platform's view controller public typealias PlatformViewController = NSViewController +/// Current platform's view controller representable public typealias PlatformVCRepresentable = NSViewControllerRepresentable +/// Current platform's view controller representable context public typealias PlatformVCRepresentableContext = NSViewControllerRepresentableContext #else /// Current platform's view type public typealias PlatformView = UIView +/// Current platform's view representable public typealias PlatformViewRepresentable = UIViewRepresentable +/// Current platform's view representable context public typealias PlatformViewRepresentableContext = UIViewRepresentableContext +/// Current platform's view controller public typealias PlatformViewController = UIViewController +/// Current platform's view controller representable public typealias PlatformVCRepresentable = UIViewControllerRepresentable +/// Current platform's view controller representable context public typealias PlatformVCRepresentableContext = UIViewControllerRepresentableContext #endif From 9902aa373426302ab6dd0a0760acc500edc32f53 Mon Sep 17 00:00:00 2001 From: Wesley de Groot Date: Tue, 23 Jul 2024 11:37:36 +0200 Subject: [PATCH 4/4] Update Inspect.swift --- Sources/Inspect/Inspect.swift | 42 ++++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/Sources/Inspect/Inspect.swift b/Sources/Inspect/Inspect.swift index a85832f..eb3a644 100644 --- a/Sources/Inspect/Inspect.swift +++ b/Sources/Inspect/Inspect.swift @@ -192,9 +192,6 @@ public enum Inspector { // Search in subviews from the entry index. for subview in superview.subviews[entryIndex..: PlatformViewRepresentable { /// /// Use this to inspect a view /// - /// How to use: - /// ```swift - /// .overlay { - /// Inspect(MyViewType()) { view - /// print(view) - /// } - /// } - /// ``` - /// /// - Parameter viewType: PlatformView /// - Parameter customizer: Customizer public init( @@ -361,7 +349,7 @@ public struct Inspect: PlatformViewRepresentable { } } -/// Introspection PlatformViewController that is inserted alongside the target view controller. +/// Inspect PlatformViewController that is inserted alongside the target view controller. public class InspectPlatformViewController: PlatformViewController { required init() { super.init(nibName: nil, bundle: nil) @@ -386,15 +374,6 @@ public struct InspectVC: PlatformVCReprese /// /// Use this to inspect a view controller /// - /// Example: - /// ```swift - /// .overlay { - /// InspectVC({ $0.tabBarController }) { view - /// print(view) - /// } - /// } - /// ``` - /// /// - Parameter selector: Selector to use /// - Parameter customizer: Customizer public init( @@ -448,7 +427,16 @@ public struct InspectVC: PlatformVCReprese } extension View { - /// Inspect + /// Inspect a PlatformView + /// + /// Use this to inspect a view + /// + /// How to use: + /// ```swift + /// .inspect(MyViewType()) { view + /// print(view) + /// } + /// ``` /// /// - Parameter element: Element to inspect /// - Parameter customizer: Element to modify @@ -469,6 +457,14 @@ extension View { /// Inspect View Controller /// + /// Use this to inspect a view controller + /// + /// ```swift + /// .inspectVC({ $0.tabBarController }) { view + /// print(view) + /// } + /// ``` + /// /// - Parameter viewControllerSelector: View controller selector /// - Parameter customizer: Element to modify public func inspect(