Skip to content

Commit f917d1c

Browse files
authored
Document some more public symbols (#273)
1 parent 67b41fa commit f917d1c

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Changelog
1313
- Added: `SignInWithAppleButton` introspection (#265)
1414
- Added: `View` introspection on macOS (#266)
1515
- Improved: `View` introspection accuracy (#266)
16+
- Documentation: added some more docs for public symbols (#273)
1617

1718
### Introspect
1819

Sources/Introspect.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import SwiftUI
22

3+
/// The scope of introspection i.e. where introspect should look to find
4+
/// the desired target view relative to the applied `.introspect(...)`
5+
/// modifier.
36
public struct IntrospectionScope: OptionSet {
7+
/// Look within the `receiver` of the `.introspect(...)` modifier.
48
public static let receiver = Self(rawValue: 1 << 0)
9+
/// Look for an `ancestor` relative to the `.introspect(...)` modifier.
510
public static let ancestor = Self(rawValue: 1 << 1)
611

712
@_spi(Private) public let rawValue: UInt
@@ -12,6 +17,28 @@ public struct IntrospectionScope: OptionSet {
1217
}
1318

1419
extension View {
20+
/// Introspects a SwiftUI view to find its underlying UIKit/AppKit instance.
21+
///
22+
/// - Parameters:
23+
/// - viewType: The type of view to be introspected.
24+
/// - platforms: A list of `PlatformViewVersions` that specify platform-specific entities associated with the view, with one or more corresponding version numbers.
25+
/// - scope: An optional `IntrospectionScope` that specifies the scope of introspection.
26+
/// - customize: A closure that hands over the underlying UIKit/AppKit instance ready for customization.
27+
///
28+
/// Here's an example usage:
29+
///
30+
/// ```swift
31+
/// struct ContentView: View {
32+
/// @State var date = Date()
33+
///
34+
/// var body: some View {
35+
/// DatePicker("Pick a date", selection: $date)
36+
/// .introspect(.datePicker, on: .iOS(.v13, .v14, .v15, .v16, .v17)) {
37+
/// print(type(of: $0)) // UIDatePicker
38+
/// }
39+
/// }
40+
/// }
41+
/// ```
1542
public func introspect<SwiftUIViewType: IntrospectableViewType, PlatformSpecificEntity: PlatformEntity>(
1643
_ viewType: SwiftUIViewType,
1744
on platforms: (PlatformViewVersions<SwiftUIViewType, PlatformSpecificEntity>)...,

Sources/IntrospectableViewType.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
public protocol IntrospectableViewType {
2+
/// The scope of introspection for this particular view type, i.e. where introspect
3+
/// should look to find the desired target view relative to the applied
4+
/// `.introspect(...)` modifier.
5+
///
6+
/// While the scope can be overridden by the user in their `.introspect(...)` call,
7+
/// most of the time it's preferable to defer to the view type's own scope,
8+
/// as it guarantees introspection is working as intended by the vendor.
9+
///
10+
/// Defaults to `.receiver` if left unimplemented, which is a sensible one in
11+
/// most cases if you're looking to implement your own view type.
212
var scope: IntrospectionScope { get }
313
}
414

0 commit comments

Comments
 (0)