From 4adb8b04100c3b6e824c72e96f33c1a381dd6b0a Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Mon, 17 Nov 2025 11:20:30 +0000 Subject: [PATCH 1/5] Add .swift-version --- .swift-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 00000000..e0ea36fe --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +6.0 From 98fc3516cd1a3d4d3185dbafc664b2c2f1f6e9db Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Mon, 17 Nov 2025 11:20:36 +0000 Subject: [PATCH 2/5] Add .swiftformat --- .swiftformat | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .swiftformat diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 00000000..a712e515 --- /dev/null +++ b/.swiftformat @@ -0,0 +1,23 @@ +# SwiftFormat Configuration File +# For documentation, see: https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md + +--header ignore +--indent tab +--ifdef preserve +--ranges preserve +--extensionacl on-declarations +--trailing-commas always +--nil-init insert + +# Disabled rules +--disable blankLinesAroundMark +--disable blankLinesBetweenScopes +--disable docComments +--disable redundantBackticks +--disable redundantLetError +--disable redundantRawValues +--disable redundantSelf +--disable redundantStaticSelf +--disable redundantType +--disable redundantTypedThrows +--disable unusedArguments From 19c5efe05ec94e7ac3e9fa79130f25e58ba31a73 Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Tue, 18 Nov 2025 08:55:02 +0000 Subject: [PATCH 3/5] Fix indentation --- Examples/Showcase/Showcase/List.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Examples/Showcase/Showcase/List.swift b/Examples/Showcase/Showcase/List.swift index 9d226268..34ed6f45 100644 --- a/Examples/Showcase/Showcase/List.swift +++ b/Examples/Showcase/Showcase/List.swift @@ -31,13 +31,13 @@ struct ListShowcase: View { .modifier { list in if #available(iOS 16, macOS 13, *) { list.background { - if receiverListFound { - Color(.cyan) - } + if receiverListFound { + Color(.cyan) } - #if !os(tvOS) - .scrollContentBackground(.hidden) - #endif + } + #if !os(tvOS) + .scrollContentBackground(.hidden) + #endif } else { list } From 891a19a493883e061a46d705540129defa563c07 Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Tue, 18 Nov 2025 08:56:43 +0000 Subject: [PATCH 4/5] Run SwiftFormat --- Examples/Package.swift | 6 ++--- Examples/Showcase/Showcase/Controls.swift | 2 -- Examples/Showcase/Showcase/List.swift | 1 - Sources/Introspect.swift | 8 +++---- Sources/IntrospectionSelector.swift | 4 ++-- Sources/IntrospectionView.swift | 9 ++++--- Sources/PlatformVersion.swift | 4 ++-- Sources/PlatformView.swift | 14 +++++------ Sources/PlatformViewVersion.swift | 24 +++++++++---------- Sources/Utils.swift | 4 ++-- Sources/Weak.swift | 2 +- Tests/Tests/TestUtils.swift | 14 +++++------ .../ToggleWithButtonStyleTests.swift | 4 ++-- Tests/Tests/ViewTypes/VideoPlayerTests.swift | 6 ++--- Tests/TestsHostApp/App.swift | 10 ++++---- 15 files changed, 54 insertions(+), 58 deletions(-) diff --git a/Examples/Package.swift b/Examples/Package.swift index dbea1ee8..b63a9509 100644 --- a/Examples/Package.swift +++ b/Examples/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let package = Package( - name: "Examples", - products: [], - targets: [] + name: "Examples", + products: [], + targets: [] ) diff --git a/Examples/Showcase/Showcase/Controls.swift b/Examples/Showcase/Showcase/Controls.swift index 3efe2dfe..22c18c2b 100644 --- a/Examples/Showcase/Showcase/Controls.swift +++ b/Examples/Showcase/Showcase/Controls.swift @@ -2,7 +2,6 @@ import SwiftUI import SwiftUIIntrospect struct ControlsShowcase: View { - @State private var textFieldValue = "" @State private var toggleValue = false @State private var sliderValue = 0.0 @@ -166,6 +165,5 @@ struct ControlsShowcase: View { #endif } } - } } diff --git a/Examples/Showcase/Showcase/List.swift b/Examples/Showcase/Showcase/List.swift index 34ed6f45..7154b45c 100644 --- a/Examples/Showcase/Showcase/List.swift +++ b/Examples/Showcase/Showcase/List.swift @@ -104,6 +104,5 @@ struct ListShowcase: View { } } } - } } diff --git a/Sources/Introspect.swift b/Sources/Introspect.swift index 0eadba26..9243f454 100644 --- a/Sources/Introspect.swift +++ b/Sources/Introspect.swift @@ -50,10 +50,10 @@ extension View { /// ``` @MainActor public func introspect( - _ viewType: SwiftUIViewType, - on platforms: (PlatformViewVersionPredicate)..., - scope: IntrospectionScope? = nil, - customize: @escaping (PlatformSpecificEntity) -> Void + _ viewType: SwiftUIViewType, + on platforms: PlatformViewVersionPredicate..., + scope: IntrospectionScope? = nil, + customize: @escaping (PlatformSpecificEntity) -> Void ) -> some View { self.modifier(IntrospectModifier(viewType, platforms: platforms, scope: scope, customize: customize)) } diff --git a/Sources/IntrospectionSelector.swift b/Sources/IntrospectionSelector.swift index 76fcbe7d..ecdba2bc 100644 --- a/Sources/IntrospectionSelector.swift +++ b/Sources/IntrospectionSelector.swift @@ -23,8 +23,8 @@ public struct IntrospectionSelector { ) } - private var receiverSelector: @MainActor (IntrospectionPlatformViewController) -> Target? - private var ancestorSelector: @MainActor (IntrospectionPlatformViewController) -> Target? + private var receiverSelector: @MainActor (IntrospectionPlatformViewController) -> Target? = nil + private var ancestorSelector: @MainActor (IntrospectionPlatformViewController) -> Target? = nil private init( receiverSelector: @MainActor @escaping (IntrospectionPlatformViewController) -> Target?, diff --git a/Sources/IntrospectionView.swift b/Sources/IntrospectionView.swift index 4885e8a8..b0929178 100644 --- a/Sources/IntrospectionView.swift +++ b/Sources/IntrospectionView.swift @@ -8,8 +8,8 @@ fileprivate enum IntrospectionStore { static var shared: [IntrospectionViewID: Pair] = [:] struct Pair { - weak var controller: IntrospectionPlatformViewController? - weak var anchor: IntrospectionAnchorPlatformViewController? + weak var controller: IntrospectionPlatformViewController? = nil + weak var anchor: IntrospectionAnchorPlatformViewController? = nil } } @@ -88,7 +88,7 @@ struct IntrospectionView: PlatformViewControllerRepresen #endif final class TargetCache { - weak var target: Target? + weak var target: Target? = nil } @Binding @@ -113,7 +113,7 @@ struct IntrospectionView: PlatformViewControllerRepresen } func makePlatformViewController(context: Context) -> IntrospectionPlatformViewController { - let controller = IntrospectionPlatformViewController(id: id) { controller in + IntrospectionPlatformViewController(id: id) { controller in guard let target = selector(controller) else { return } @@ -121,7 +121,6 @@ struct IntrospectionView: PlatformViewControllerRepresen customize(target) controller.handler = nil } - return controller } func updatePlatformViewController(_ controller: IntrospectionPlatformViewController, context: Context) { diff --git a/Sources/PlatformVersion.swift b/Sources/PlatformVersion.swift index 771eee7f..40066600 100644 --- a/Sources/PlatformVersion.swift +++ b/Sources/PlatformVersion.swift @@ -23,7 +23,7 @@ extension PlatformVersion { public var isCurrentOrPast: Bool { condition == .current || condition == .past } - + @_spi(Internals) public var condition: PlatformVersionCondition? { nil } } @@ -206,7 +206,7 @@ extension tvOSVersion { return nil #endif } - + public static let v17 = tvOSVersion { #if os(tvOS) if #available(tvOS 18, *) { diff --git a/Sources/PlatformView.swift b/Sources/PlatformView.swift index c5c406e8..a661c69f 100644 --- a/Sources/PlatformView.swift +++ b/Sources/PlatformView.swift @@ -36,25 +36,25 @@ public protocol PlatformViewControllerRepresentable: _PlatformViewControllerRepr } @_spi(Internals) -public extension PlatformViewControllerRepresentable { +extension PlatformViewControllerRepresentable { #if canImport(UIKit) - func makeUIViewController(context: Context) -> ViewController { + public func makeUIViewController(context: Context) -> ViewController { makePlatformViewController(context: context) } - func updateUIViewController(_ controller: ViewController, context: Context) { + public func updateUIViewController(_ controller: ViewController, context: Context) { updatePlatformViewController(controller, context: context) } - static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) { + public static func dismantleUIViewController(_ controller: ViewController, coordinator: Coordinator) { dismantlePlatformViewController(controller, coordinator: coordinator) } #elseif canImport(AppKit) - func makeNSViewController(context: Context) -> ViewController { + public func makeNSViewController(context: Context) -> ViewController { makePlatformViewController(context: context) } - func updateNSViewController(_ controller: ViewController, context: Context) { + public func updateNSViewController(_ controller: ViewController, context: Context) { updatePlatformViewController(controller, context: context) } - static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) { + public static func dismantleNSViewController(_ controller: ViewController, coordinator: Coordinator) { dismantlePlatformViewController(controller, coordinator: coordinator) } #endif diff --git a/Sources/PlatformViewVersion.swift b/Sources/PlatformViewVersion.swift index bce22767..fb953d2f 100644 --- a/Sources/PlatformViewVersion.swift +++ b/Sources/PlatformViewVersion.swift @@ -16,7 +16,7 @@ public struct PlatformViewVersionPredicate)...) -> Self { + public static func iOS(_ versions: iOSViewVersion...) -> Self { Self(versions, matches: \.isCurrent) } @@ -25,7 +25,7 @@ public struct PlatformViewVersionPredicate)...) -> Self { + public static func tvOS(_ versions: tvOSViewVersion...) -> Self { Self(versions, matches: \.isCurrent) } @@ -34,7 +34,7 @@ public struct PlatformViewVersionPredicate)...) -> Self { + public static func macOS(_ versions: macOSViewVersion...) -> Self { Self(versions, matches: \.isCurrent) } @@ -43,7 +43,7 @@ public struct PlatformViewVersionPredicate)...) -> Self { + public static func visionOS(_ versions: visionOSViewVersion...) -> Self { Self(versions, matches: \.isCurrent) } @@ -89,19 +89,19 @@ public enum PlatformViewVersion? { - if case .available(_, let selector) = self { - return selector + if case let .available(_, selector) = self { + selector } else { - return nil + nil } } @@ -117,11 +117,11 @@ public enum PlatformViewVersion Bool { + public nonisolated static func == (lhs: Self, rhs: Self) -> Bool { true } - nonisolated public static func < (lhs: Self, rhs: Self) -> Bool { + public nonisolated static func < (lhs: Self, rhs: Self) -> Bool { true } } diff --git a/Sources/Utils.swift b/Sources/Utils.swift index 7848311e..697424b7 100644 --- a/Sources/Utils.swift +++ b/Sources/Utils.swift @@ -1,10 +1,10 @@ postfix operator ~ -postfix func ~ (lhs: LHS) -> T { +postfix func ~ (lhs: some Any) -> T { lhs as! T } -postfix func ~ (lhs: LHS?) -> T? { +postfix func ~ (lhs: (some Any)?) -> T? { lhs as? T } diff --git a/Sources/Weak.swift b/Sources/Weak.swift index 4560aca3..8084c5ab 100644 --- a/Sources/Weak.swift +++ b/Sources/Weak.swift @@ -1,7 +1,7 @@ @_spi(Advanced) @propertyWrapper public final class Weak { - private weak var _wrappedValue: T? + private weak var _wrappedValue: T? = nil public var wrappedValue: T? { get { _wrappedValue } diff --git a/Tests/Tests/TestUtils.swift b/Tests/Tests/TestUtils.swift index fa1c1afc..d31dc7e8 100644 --- a/Tests/Tests/TestUtils.swift +++ b/Tests/Tests/TestUtils.swift @@ -58,7 +58,7 @@ func introspection( { confirmation1() entity1 = $0 - }, + } ) TestUtils.present(view: view) @@ -98,7 +98,7 @@ func introspection( { confirmation2() entity2 = $0 - }, + } ) TestUtils.present(view: view) @@ -114,7 +114,7 @@ func introspection( return try ( #require(entity1, sourceLocation: sourceLocation), - #require(entity2, sourceLocation: sourceLocation), + #require(entity2, sourceLocation: sourceLocation) ) } } @@ -150,7 +150,7 @@ func introspection( { confirmation3() entity3 = $0 - }, + } ) TestUtils.present(view: view) @@ -168,7 +168,7 @@ func introspection( return try ( #require(entity1, sourceLocation: sourceLocation), #require(entity2, sourceLocation: sourceLocation), - #require(entity3, sourceLocation: sourceLocation), + #require(entity3, sourceLocation: sourceLocation) ) } } @@ -212,7 +212,7 @@ func introspection( { confirmation4() entity4 = $0 - }, + } ) TestUtils.present(view: view) @@ -232,7 +232,7 @@ func introspection( #require(entity1, sourceLocation: sourceLocation), #require(entity2, sourceLocation: sourceLocation), #require(entity3, sourceLocation: sourceLocation), - #require(entity4, sourceLocation: sourceLocation), + #require(entity4, sourceLocation: sourceLocation) ) } } diff --git a/Tests/Tests/ViewTypes/ToggleWithButtonStyleTests.swift b/Tests/Tests/ViewTypes/ToggleWithButtonStyleTests.swift index e605503d..58849e6f 100644 --- a/Tests/Tests/ViewTypes/ToggleWithButtonStyleTests.swift +++ b/Tests/Tests/ViewTypes/ToggleWithButtonStyleTests.swift @@ -15,11 +15,11 @@ struct ToggleWithButtonStyleTests { Toggle("", isOn: .constant(true)) .toggleStyle(.button) .introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy1) - + Toggle("", isOn: .constant(false)) .toggleStyle(.button) .introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy2) - + Toggle("", isOn: .constant(true)) .toggleStyle(.button) .introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy3) diff --git a/Tests/Tests/ViewTypes/VideoPlayerTests.swift b/Tests/Tests/ViewTypes/VideoPlayerTests.swift index 92ab1f43..f559bcbb 100644 --- a/Tests/Tests/ViewTypes/VideoPlayerTests.swift +++ b/Tests/Tests/ViewTypes/VideoPlayerTests.swift @@ -14,9 +14,9 @@ struct VideoPlayerTests { #endif @Test func introspect() async throws { - let videoURL1 = URL(string: "https://bit.ly/swswift#1")! - let videoURL2 = URL(string: "https://bit.ly/swswift#2")! - let videoURL3 = URL(string: "https://bit.ly/swswift#3")! + let videoURL1 = try #require(URL(string: "https://bit.ly/swswift#1")) + let videoURL2 = try #require(URL(string: "https://bit.ly/swswift#2")) + let videoURL3 = try #require(URL(string: "https://bit.ly/swswift#3")) let (entity1, entity2, entity3) = try await introspection(of: PlatformVideoPlayer.self) { spy1, spy2, spy3 in VStack { diff --git a/Tests/TestsHostApp/App.swift b/Tests/TestsHostApp/App.swift index 050f4177..abed6a52 100644 --- a/Tests/TestsHostApp/App.swift +++ b/Tests/TestsHostApp/App.swift @@ -2,9 +2,9 @@ import SwiftUI @main struct App: SwiftUI.App { - var body: some Scene { - WindowGroup { - EmptyView() - } - } + var body: some Scene { + WindowGroup { + EmptyView() + } + } } From 280cec2d348653686233903e010d1d351cd8e348 Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Tue, 18 Nov 2025 15:13:51 +0000 Subject: [PATCH 5/5] WIP --- Sources/IntrospectionSelector.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/IntrospectionSelector.swift b/Sources/IntrospectionSelector.swift index ecdba2bc..76fcbe7d 100644 --- a/Sources/IntrospectionSelector.swift +++ b/Sources/IntrospectionSelector.swift @@ -23,8 +23,8 @@ public struct IntrospectionSelector { ) } - private var receiverSelector: @MainActor (IntrospectionPlatformViewController) -> Target? = nil - private var ancestorSelector: @MainActor (IntrospectionPlatformViewController) -> Target? = nil + private var receiverSelector: @MainActor (IntrospectionPlatformViewController) -> Target? + private var ancestorSelector: @MainActor (IntrospectionPlatformViewController) -> Target? private init( receiverSelector: @MainActor @escaping (IntrospectionPlatformViewController) -> Target?,