Skip to content

Commit 5fc6b0e

Browse files
authored
Documentation for new SwiftUIIntrospect module (#258)
1 parent 8d85155 commit 5fc6b0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+943
-117
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
name: Install Required Runtime (${{ matrix.runtime }})
118118
uses: nick-fields/retry@v2
119119
with:
120-
timeout_minutes: 12
120+
timeout_minutes: 15
121121
max_attempts: 3
122122
command: sudo xcodes runtimes install '${{ matrix.runtime }}'
123123

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import SwiftUI
22

33
extension View {
4-
@ViewBuilder
5-
func modifier<TransformedView: View>(
6-
@ViewBuilder transform: (Self) -> TransformedView
7-
) -> TransformedView {
8-
transform(self)
4+
/// Modify a view with a `ViewBuilder` closure.
5+
///
6+
/// This represents a streamlining of the
7+
/// [`modifier`](https://developer.apple.com/documentation/swiftui/view/modifier(_:)) +
8+
/// [`ViewModifier`](https://developer.apple.com/documentation/swiftui/viewmodifier) pattern.
9+
///
10+
/// - Note: Useful only when you don't need to reuse the closure.
11+
/// If you do, turn the closure into a proper modifier.
12+
public func modifier<ModifiedContent: View>(
13+
@ViewBuilder _ modifier: (Self) -> ModifiedContent
14+
) -> ModifiedContent {
15+
modifier(self)
916
}
1017
}

Sources/ViewTypes/Button.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
#if os(macOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.Button
5-
3+
/// An abstract representation of the `Button` type in SwiftUI.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// var body: some View {
8+
/// Button("Action", action: {})
9+
/// #if os(macOS)
10+
/// .introspect(.button, on: .macOS(.v10_15, .v11, .v12, .v13, .v14)) {
11+
/// print(type(of: $0)) // NSButton
12+
/// }
13+
/// #endif
14+
/// }
15+
/// }
16+
/// ```
617
public struct ButtonType: IntrospectableViewType {}
718

19+
#if os(macOS)
820
extension IntrospectableViewType where Self == ButtonType {
921
public static var button: Self { .init() }
1022
}

Sources/ViewTypes/ColorPicker.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
#if !os(tvOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.ColorPicker
5-
3+
/// An abstract representation of the `ColorPicker` type in SwiftUI.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var color = Color.red
8+
///
9+
/// var body: some View {
10+
/// ColorPicker("Pick a color", selection: $color)
11+
/// #if os(iOS)
12+
/// .introspect(.colorPicker, on: .iOS(.v14, .v15, .v16, .v17)) {
13+
/// print(type(of: $0)) // UIColorPicker
14+
/// }
15+
/// #elseif os(macOS)
16+
/// .introspect(.colorPicker, on: .macOS(.v11, .v12, .v13, .v14)) {
17+
/// print(type(of: $0)) // NSColorPicker
18+
/// }
19+
/// #endif
20+
/// }
21+
/// }
22+
/// ```
623
public struct ColorPickerType: IntrospectableViewType {}
724

25+
#if !os(tvOS)
826
extension IntrospectableViewType where Self == ColorPickerType {
927
public static var colorPicker: Self { .init() }
1028
}

Sources/ViewTypes/DatePicker.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
#if os(iOS) || os(macOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.DatePicker
5-
3+
/// An abstract representation of the `DatePicker` type in SwiftUI.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var date = Date()
8+
///
9+
/// var body: some View {
10+
/// DatePicker("Pick a date", selection: $date)
11+
/// #if os(iOS)
12+
/// .introspect(.datePicker, on: .iOS(.v13, .v14, .v15, .v16, .v17)) {
13+
/// print(type(of: $0)) // UIDatePicker
14+
/// }
15+
/// #elseif os(macOS)
16+
/// .introspect(.datePicker, on: .macOS(.v10_15, .v11, .v12, .v13, .v14)) {
17+
/// print(type(of: $0)) // NSDatePicker
18+
/// }
19+
/// #endif
20+
/// }
21+
/// }
22+
/// ```
623
public struct DatePickerType: IntrospectableViewType {}
724

25+
#if os(iOS) || os(macOS)
826
extension IntrospectableViewType where Self == DatePickerType {
927
public static var datePicker: Self { .init() }
1028
}

Sources/ViewTypes/DatePickerWithCompactStyle.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
#if os(iOS) || os(macOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.DatePicker { ... }.datePickerStyle(.compact)
5-
3+
/// An abstract representation of the `DatePicker` type in SwiftUI, with `.compact` style.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var date = Date()
8+
///
9+
/// var body: some View {
10+
/// DatePicker("Pick a date", selection: $date)
11+
/// .datePickerStyle(.compact)
12+
/// #if os(iOS)
13+
/// .introspect(.datePicker(style: .compact), on: .iOS(.v14, .v15, .v16, .v17)) {
14+
/// print(type(of: $0)) // UIDatePicker
15+
/// }
16+
/// #elseif os(macOS)
17+
/// .introspect(.datePicker(style: .compact), on: .macOS(.v10_15_4, .v11, .v12, .v13, .v14)) {
18+
/// print(type(of: $0)) // NSDatePicker
19+
/// }
20+
/// #endif
21+
/// }
22+
/// }
23+
/// ```
624
public struct DatePickerWithCompactStyleType: IntrospectableViewType {
725
public enum Style {
826
case compact
927
}
1028
}
1129

30+
#if os(iOS) || os(macOS)
1231
extension IntrospectableViewType where Self == DatePickerWithCompactStyleType {
1332
public static func datePicker(style: Self.Style) -> Self { .init() }
1433
}

Sources/ViewTypes/DatePickerWithFieldStyle.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
#if os(macOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.DatePicker { ... }.datePickerStyle(.field)
5-
3+
/// An abstract representation of the `DatePicker` type in SwiftUI, with `.field` style.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var date = Date()
8+
///
9+
/// var body: some View {
10+
/// DatePicker("Pick a date", selection: $date)
11+
/// .datePickerStyle(.field)
12+
/// #if os(macOS)
13+
/// .introspect(.datePicker(style: .field), on: .macOS(.v10_15, .v11, .v12, .v13, .v14)) {
14+
/// print(type(of: $0)) // NSDatePicker
15+
/// }
16+
/// #endif
17+
/// }
18+
/// }
19+
/// ```
620
public struct DatePickerWithFieldStyleType: IntrospectableViewType {
721
public enum Style {
822
case field
923
}
1024
}
1125

26+
#if os(macOS)
1227
extension IntrospectableViewType where Self == DatePickerWithFieldStyleType {
1328
public static func datePicker(style: Self.Style) -> Self { .init() }
1429
}

Sources/ViewTypes/DatePickerWithGraphicalStyleType.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
#if os(iOS) || os(macOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.DatePicker { ... }.datePickerStyle(.graphical)
5-
3+
/// An abstract representation of the `DatePicker` type in SwiftUI, with `.graphical` style.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var date = Date()
8+
///
9+
/// var body: some View {
10+
/// DatePicker("Pick a date", selection: $date)
11+
/// .datePickerStyle(.graphical)
12+
/// #if os(iOS)
13+
/// .introspect(.datePicker(style: .graphical), on: .iOS(.v14, .v15, .v16, .v17)) {
14+
/// print(type(of: $0)) // UIDatePicker
15+
/// }
16+
/// #elseif os(macOS)
17+
/// .introspect(.datePicker(style: .graphical), on: .macOS(.v10_15, .v11, .v12, .v13, .v14)) {
18+
/// print(type(of: $0)) // NSDatePicker
19+
/// }
20+
/// #endif
21+
/// }
22+
/// }
23+
/// ```
624
public struct DatePickerWithGraphicalStyleType: IntrospectableViewType {
725
public enum Style {
826
case graphical
927
}
1028
}
1129

30+
#if os(iOS) || os(macOS)
1231
extension IntrospectableViewType where Self == DatePickerWithGraphicalStyleType {
1332
public static func datePicker(style: Self.Style) -> Self { .init() }
1433
}

Sources/ViewTypes/DatePickerWithStepperFieldStyle.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
#if os(macOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.DatePicker { ... }.datePickerStyle(.stepperField)
5-
3+
/// An abstract representation of the `DatePicker` type in SwiftUI, with `.stepperField` style.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var date = Date()
8+
///
9+
/// var body: some View {
10+
/// DatePicker("Pick a date", selection: $date)
11+
/// .datePickerStyle(.stepperField)
12+
/// #if os(macOS)
13+
/// .introspect(.datePicker(style: .stepperField), on: .macOS(.v10_15, .v11, .v12, .v13, .v14)) {
14+
/// print(type(of: $0)) // NSDatePicker
15+
/// }
16+
/// #endif
17+
/// }
18+
/// }
19+
/// ```
620
public struct DatePickerWithStepperFieldStyleType: IntrospectableViewType {
721
public enum Style {
822
case stepperField
923
}
1024
}
1125

26+
#if os(macOS)
1227
extension IntrospectableViewType where Self == DatePickerWithStepperFieldStyleType {
1328
public static func datePicker(style: Self.Style) -> Self { .init() }
1429
}

Sources/ViewTypes/DatePickerWithWheelStyle.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1-
#if os(iOS)
21
import SwiftUI
32

4-
// MARK: SwiftUI.DatePicker { ... }.datePickerStyle(.wheel)
5-
3+
/// An abstract representation of the `DatePicker` type in SwiftUI, with `.wheel` style.
4+
///
5+
/// ```swift
6+
/// struct ContentView: View {
7+
/// @State var date = Date()
8+
///
9+
/// var body: some View {
10+
/// DatePicker("Pick a date", selection: $date)
11+
/// .datePickerStyle(.wheel)
12+
/// #if os(iOS)
13+
/// .introspect(.datePicker(style: .wheel), on: .iOS(.v13, .v14, .v15, .v16, .v17)) {
14+
/// print(type(of: $0)) // UIDatePicker
15+
/// }
16+
/// #endif
17+
/// }
18+
/// }
19+
/// ```
620
public struct DatePickerWithWheelStyleType: IntrospectableViewType {
721
public enum Style {
822
case wheel
923
}
1024
}
1125

26+
#if os(iOS)
1227
extension IntrospectableViewType where Self == DatePickerWithWheelStyleType {
1328
public static func datePicker(style: Self.Style) -> Self { .init() }
1429
}

0 commit comments

Comments
 (0)