Skip to content

Commit fd95241

Browse files
committed
Add support for installing on older OS versions #28
1 parent 1a3d3c8 commit fd95241

9 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Changelog
33

44
## master
55

6+
- Allow `Introspect` to be imported in apps that support older platform versions.
7+
68
## [0.1.0]
79

810
- Added `macOS` and `tvOS` support.

Introspect/AppKitIntrospectionView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import AppKit
44

55
/// Introspection NSView that is inserted alongside the target view.
6+
@available(macOS 15.0, *)
67
public class IntrospectionNSView: NSView {
78

89
required init() {
@@ -22,6 +23,7 @@ public class IntrospectionNSView: NSView {
2223

2324
/// Introspection View that is injected into the UIKit hierarchy alongside the target view.
2425
/// After `updateNSView` is called, it calls `selector` to find the target view, then `customize` when the target view is found.
26+
@available(macOS 15.0, *)
2527
public struct AppKitIntrospectionView<TargetViewType: NSView>: NSViewRepresentable {
2628

2729
/// Method that introspects the view hierarchy to find the target view.

Introspect/Introspect.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public enum Introspect {
190190
}
191191
}
192192

193-
enum TargetViewSelector {
193+
public enum TargetViewSelector {
194194
public static func sibling<TargetView: PlatformView>(from entry: PlatformView) -> TargetView? {
195195
guard let viewHost = Introspect.findViewHost(from: entry) else {
196196
return nil

Introspect/UIKitIntrospectionView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import UIKit
33
import SwiftUI
44

55
/// Introspection UIView that is inserted alongside the target view.
6+
@available(iOS 13.0, *)
67
public class IntrospectionUIView: UIView {
78

89
required init() {
@@ -19,6 +20,7 @@ public class IntrospectionUIView: UIView {
1920

2021
/// Introspection View that is injected into the UIKit hierarchy alongside the target view.
2122
/// After `updateUIView` is called, it calls `selector` to find the target view, then `customize` when the target view is found.
23+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
2224
public struct UIKitIntrospectionView<TargetViewType: UIView>: UIViewRepresentable {
2325

2426
/// Method that introspects the view hierarchy to find the target view.

Introspect/UIKitIntrospectionViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33
import UIKit
44

55
/// Introspection UIViewController that is inserted alongside the target view controller.
6+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
67
public class IntrospectionUIViewController: UIViewController {
78
required init() {
89
super.init(nibName: nil, bundle: nil)
@@ -16,6 +17,7 @@ public class IntrospectionUIViewController: UIViewController {
1617
}
1718

1819
/// This is the same logic as IntrospectionView but for view controllers. Please see details above.
20+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
1921
public struct UIKitIntrospectionViewController<TargetViewControllerType: UIViewController>: UIViewControllerRepresentable {
2022

2123
let selector: (IntrospectionUIViewController) -> TargetViewControllerType?

Introspect/ViewExtensions.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import AppKit
66
import UIKit
77
#endif
88

9+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
910
extension View {
1011
public func inject<SomeView>(_ view: SomeView) -> some View where SomeView: View {
1112
return overlay(view.frame(width: 0, height: 0))
1213
}
1314
}
1415

1516
#if canImport(UIKit)
17+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
1618
extension View {
1719

1820
/// Finds a `TargetView` from a `SwiftUI.View`
@@ -115,6 +117,7 @@ extension View {
115117
#endif
116118

117119
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
120+
@available(macOS 15.0, *)
118121
extension View {
119122

120123
/// Finds a `TargetView` from a `SwiftUI.View`

IntrospectTests/AppKitTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import XCTest
44
import SwiftUI
55
@testable import Introspect
66

7+
@available(macOS 15.0, *)
78
enum TestUtils {
89
static func present<ViewType: View>(view: ViewType) {
910

@@ -18,6 +19,7 @@ enum TestUtils {
1819
}
1920
}
2021

22+
@available(macOS 15.0, *)
2123
private struct ListTestView: View {
2224

2325
let spy1: () -> Void
@@ -37,6 +39,7 @@ private struct ListTestView: View {
3739
}
3840
}
3941

42+
@available(macOS 15.0, *)
4043
private struct ScrollTestView: View {
4144

4245
let spy1: () -> Void
@@ -60,6 +63,7 @@ private struct ScrollTestView: View {
6063
}
6164
}
6265

66+
@available(macOS 15.0, *)
6367
private struct TextFieldTestView: View {
6468
let spy: () -> Void
6569
@State private var textFieldValue = ""
@@ -71,6 +75,7 @@ private struct TextFieldTestView: View {
7175
}
7276
}
7377

78+
@available(macOS 15.0, *)
7479
private struct SliderTestView: View {
7580
let spy: () -> Void
7681
@State private var sliderValue = 0.0
@@ -82,6 +87,7 @@ private struct SliderTestView: View {
8287
}
8388
}
8489

90+
@available(macOS 15.0, *)
8591
private struct StepperTestView: View {
8692
let spy: () -> Void
8793
var body: some View {
@@ -94,6 +100,7 @@ private struct StepperTestView: View {
94100
}
95101
}
96102

103+
@available(macOS 15.0, *)
97104
private struct DatePickerTestView: View {
98105
let spy: () -> Void
99106
@State private var datePickerValue = Date()
@@ -107,6 +114,7 @@ private struct DatePickerTestView: View {
107114
}
108115
}
109116

117+
@available(macOS 15.0, *)
110118
private struct SegmentedControlTestView: View {
111119
@State private var pickerValue = 0
112120
let spy: () -> Void
@@ -123,6 +131,7 @@ private struct SegmentedControlTestView: View {
123131
}
124132
}
125133

134+
@available(macOS 15.0, *)
126135
class AppKitTests: XCTestCase {
127136

128137
func testList() {

IntrospectTests/UIKitTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SwiftUI
44

55
@testable import Introspect
66

7+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
78
enum TestUtils {
89
static func present<ViewType: View>(view: ViewType) {
910

@@ -27,6 +28,7 @@ enum TestUtils {
2728
}
2829
}
2930

31+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
3032
private struct NavigationTestView: View {
3133
let spy: () -> Void
3234
var body: some View {
@@ -41,6 +43,7 @@ private struct NavigationTestView: View {
4143
}
4244
}
4345

46+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
4447
private struct ViewControllerTestView: View {
4548
let spy: () -> Void
4649
var body: some View {
@@ -55,6 +58,7 @@ private struct ViewControllerTestView: View {
5558
}
5659
}
5760

61+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
5862
private struct NavigationRootTestView: View {
5963
let spy: () -> Void
6064
var body: some View {
@@ -69,6 +73,7 @@ private struct NavigationRootTestView: View {
6973
}
7074
}
7175

76+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
7277
private struct TabTestView: View {
7378
@State private var selection = 0
7479
let spy: () -> Void
@@ -83,6 +88,7 @@ private struct TabTestView: View {
8388
}
8489
}
8590

91+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
8692
private struct TabRootTestView: View {
8793
@State private var selection = 0
8894
let spy: () -> Void
@@ -97,6 +103,7 @@ private struct TabRootTestView: View {
97103
}
98104
}
99105

106+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
100107
private struct ListTestView: View {
101108

102109
let spy1: () -> Void
@@ -116,6 +123,7 @@ private struct ListTestView: View {
116123
}
117124
}
118125

126+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
119127
private struct ScrollTestView: View {
120128

121129
let spy1: () -> Void
@@ -139,6 +147,7 @@ private struct ScrollTestView: View {
139147
}
140148
}
141149

150+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
142151
private struct TextFieldTestView: View {
143152
let spy: () -> Void
144153
@State private var textFieldValue = ""
@@ -150,6 +159,7 @@ private struct TextFieldTestView: View {
150159
}
151160
}
152161

162+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
153163
@available(tvOS, unavailable)
154164
private struct ToggleTestView: View {
155165
let spy: () -> Void
@@ -162,6 +172,7 @@ private struct ToggleTestView: View {
162172
}
163173
}
164174

175+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
165176
@available(tvOS, unavailable)
166177
private struct SliderTestView: View {
167178
let spy: () -> Void
@@ -174,6 +185,7 @@ private struct SliderTestView: View {
174185
}
175186
}
176187

188+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
177189
@available(tvOS, unavailable)
178190
private struct StepperTestView: View {
179191
let spy: () -> Void
@@ -187,6 +199,7 @@ private struct StepperTestView: View {
187199
}
188200
}
189201

202+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
190203
@available(tvOS, unavailable)
191204
private struct DatePickerTestView: View {
192205
let spy: () -> Void
@@ -201,6 +214,7 @@ private struct DatePickerTestView: View {
201214
}
202215
}
203216

217+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
204218
private struct SegmentedControlTestView: View {
205219
@State private var pickerValue = 0
206220
let spy: () -> Void
@@ -217,6 +231,7 @@ private struct SegmentedControlTestView: View {
217231
}
218232
}
219233

234+
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
220235
class UIKitTests: XCTestCase {
221236
func testNavigation() {
222237

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import PackageDescription
55
let package = Package(
66
name: "Introspect",
77
platforms: [
8-
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)
8+
.macOS(.v10_13),
9+
.iOS(.v11),
10+
.tvOS(.v11)
911
],
1012
products: [
1113
.library(

0 commit comments

Comments
 (0)