Skip to content

Commit ebec259

Browse files
authored
Mark unavailable macOS 26 introspections (#489)
1 parent 5cf6b4b commit ebec259

File tree

4 files changed

+90
-44
lines changed

4 files changed

+90
-44
lines changed

Sources/ViewTypes/Button.swift

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,60 @@
99
///
1010
/// Not available.
1111
///
12-
/// ### macOS
12+
/// ### macOS 10.15 – 15
1313
///
1414
/// ```swift
1515
/// struct ContentView: View {
1616
/// var body: some View {
17-
/// Button("Action", action: {})
18-
/// .introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26)) {
19-
/// print(type(of: $0)) // NSButton
20-
/// }
17+
/// VStack {
18+
/// Button("Plain Button", action: {})
19+
/// .introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15)) {
20+
/// print(type(of: $0)) // NSButton
21+
/// }
22+
///
23+
/// Button("Bordered Button", action: {})
24+
/// .buttonStyle(.bordered)
25+
/// .introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15)) {
26+
/// print(type(of: $0)) // NSButton
27+
/// }
28+
///
29+
/// Button("Borderless Button", action: {})
30+
/// .buttonStyle(.borderless)
31+
/// .introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15)) {
32+
/// print(type(of: $0)) // NSButton
33+
/// }
34+
///
35+
/// Button("Link Button", action: {})
36+
/// .buttonStyle(.link)
37+
/// .introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15)) {
38+
/// print(type(of: $0)) // NSButton
39+
/// }
40+
/// }
41+
/// }
42+
/// }
43+
/// ```
44+
///
45+
/// ### macOS 26
46+
///
47+
/// On macOS 26, only the `.borderless` and `.link` button styles are supported for introspection.
48+
/// Other styles (e.g., plain or bordered) are not supported on macOS 26.
49+
///
50+
/// ```swift
51+
/// struct ContentView: View {
52+
/// var body: some View {
53+
/// VStack {
54+
/// Button("Borderless Button", action: {})
55+
/// .buttonStyle(.borderless)
56+
/// .introspect(.button, on: .macOS(.v26)) {
57+
/// print(type(of: $0)) // NSButton
58+
/// }
59+
///
60+
/// Button("Link Button", action: {})
61+
/// .buttonStyle(.link)
62+
/// .introspect(.button, on: .macOS(.v26)) {
63+
/// print(type(of: $0)) // NSButton
64+
/// }
65+
/// }
2166
/// }
2267
/// }
2368
/// ```

Sources/ViewTypes/ToggleWithButtonStyle.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
///
1010
/// Not available.
1111
///
12-
/// ### macOS
12+
/// ### macOS 10.15 - 15
13+
///
14+
/// Note: On macOS 26 and later, toggles with button style are no longer backed by `NSButton`, so introspection is
15+
/// not possible.
1316
///
1417
/// ```swift
1518
/// struct ContentView: View {
@@ -18,7 +21,7 @@
1821
/// var body: some View {
1922
/// Toggle("Toggle", isOn: $isOn)
2023
/// .toggleStyle(.button)
21-
/// .introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15, .v26)) {
24+
/// .introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15)) {
2225
/// print(type(of: $0)) // NSButton
2326
/// }
2427
/// }
@@ -51,7 +54,8 @@ extension macOSViewVersion<ToggleWithButtonStyleType, NSButton> {
5154
public static let v13 = Self(for: .v13)
5255
public static let v14 = Self(for: .v14)
5356
public static let v15 = Self(for: .v15)
54-
public static let v26 = Self(for: .v26)
57+
@available(*, unavailable, message: ".toggleStyle(.button) isn't available on macOS 26")
58+
public static let v26 = Self.unavailable
5559
}
5660
#endif
5761
#endif

Tests/Tests/ViewTypes/ButtonTests.swift

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,43 @@ struct ButtonTests {
1010
typealias PlatformButton = NSButton
1111
#endif
1212

13-
@Test func introspect() async throws {
13+
@available(macOS, introduced: 10.15, obsoleted: 26.0)
14+
@Test func introspectButtonsBeforeMacOS26() async throws {
1415
let (entity1, entity2, entity3, entity4) = try await introspection(of: PlatformButton.self) { spy1, spy2, spy3, spy4 in
1516
VStack {
16-
Button("Button 0", action: {})
17+
Button("Plain Button", action: {})
18+
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15), customize: spy1)
19+
20+
Button("Bordered Button", action: {})
1721
.buttonStyle(.bordered)
18-
#if os(macOS)
19-
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy1)
20-
#endif
22+
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15), customize: spy2)
2123

22-
Button("Button 1", action: {})
24+
Button("Borderless Button", action: {})
2325
.buttonStyle(.borderless)
24-
#if os(macOS)
25-
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy2)
26-
#endif
26+
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15), customize: spy3)
2727

28-
Button("Button 2", action: {})
28+
Button("Link Button", action: {})
2929
.buttonStyle(.link)
30-
#if os(macOS)
31-
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy3)
32-
#endif
33-
34-
Button("Button 3", action: {})
35-
#if os(macOS)
36-
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy4)
37-
#endif
30+
.introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15), customize: spy4)
3831
}
3932
}
40-
#if canImport(AppKit)
4133
#expect(Set([entity1, entity2, entity3, entity4].map(ObjectIdentifier.init)).count == 4)
42-
#endif
34+
}
35+
36+
@available(macOS 26, *)
37+
@Test func introspectButtonsOnMacOS26() async throws {
38+
let (entity1, entity2) = try await introspection(of: NSButton.self) { spy1, spy2 in
39+
VStack {
40+
Button("Borderless Button", action: {})
41+
.buttonStyle(.borderless)
42+
.introspect(.button, on: .macOS(.v26), customize: spy1)
43+
44+
Button("Link Button", action: {})
45+
.buttonStyle(.link)
46+
.introspect(.button, on: .macOS(.v26), customize: spy2)
47+
}
48+
}
49+
#expect(Set([entity1, entity2].map(ObjectIdentifier.init)).count == 2)
4350
}
4451
}
4552
#endif

Tests/Tests/ViewTypes/ToggleWithButtonStyleTests.swift

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,28 @@ import Testing
66
@MainActor
77
@Suite
88
struct ToggleWithButtonStyleTests {
9-
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
109
typealias PlatformToggleWithButtonStyle = NSButton
11-
#endif
1210

13-
@available(macOS 12, *)
11+
@available(macOS, introduced: 12, obsoleted: 26)
1412
@Test func introspect() async throws {
1513
let (entity1, entity2, entity3) = try await introspection(of: PlatformToggleWithButtonStyle.self) { spy1, spy2, spy3 in
1614
VStack {
1715
Toggle("", isOn: .constant(true))
1816
.toggleStyle(.button)
19-
#if os(macOS)
20-
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15, .v26), customize: spy1)
21-
#endif
22-
17+
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy1)
18+
2319
Toggle("", isOn: .constant(false))
2420
.toggleStyle(.button)
25-
#if os(macOS)
26-
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15, .v26), customize: spy2)
27-
#endif
28-
21+
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy2)
22+
2923
Toggle("", isOn: .constant(true))
3024
.toggleStyle(.button)
31-
#if os(macOS)
32-
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15, .v26), customize: spy3)
33-
#endif
25+
.introspect(.toggle(style: .button), on: .macOS(.v12, .v13, .v14, .v15), customize: spy3)
3426
}
3527
}
36-
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
3728
#expect(entity1.state == .on)
3829
#expect(entity2.state == .off)
3930
#expect(entity3.state == .on)
40-
#endif
4131
}
4232
}
4333
#endif

0 commit comments

Comments
 (0)