Skip to content

Commit 9b50f11

Browse files
Merge pull request #24 from ConsultingMD/feature/add-sibling-modifier
Add sibling debug scan modifier + tests
2 parents 48d063e + 105427e commit 9b50f11

File tree

3 files changed

+384
-1
lines changed

3 files changed

+384
-1
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
## [0.3.0] - 2025-11-17
11+
### Added
12+
- Type-based `debugScan` modifier sibling function for type-safe view debugging
13+
- New overload: `debugScan(_ label: (some View).Type)` that derives labels from Swift types
14+
- Uses `String(describing:)` to automatically generate consistent debug labels from view types
15+
- Provides type-safety and refactor-resilience compared to manual string labels
16+
- Requires explicit type specification (e.g., `Text.self`, `MyCustomView.self`) to avoid Swift type inference issues
17+
- Comprehensive test coverage with 6 additional test cases covering type resolution, custom views, and explicit type specification
18+
- Enhanced documentation for both string-based and type-based `debugScan` variants with cross-references
19+
820
## [0.2.0] - 2025-10-28
921
### Added
1022
- Comprehensive test suite with 800+ lines of test code

Sources/SwiftUIDebugScan/DebugScan.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public extension View {
167167
/// - filePath: The full file path where the view is defined. Defaults to the current file path (`#filePath`).
168168
///
169169
/// - Returns: A modified view with debug instrumentation applied.
170+
///
171+
/// - SeeAlso: `debugScan(_:file:fileID:filePath:)` for the type-based variant that automatically derives labels from view types.
170172
func debugScan(
171173
_ label: String,
172174
file: StaticString = #file,
@@ -182,4 +184,40 @@ public extension View {
182184
)
183185
)
184186
}
187+
188+
/// Adds a debug instrumentation modifier to the view for logging and tracking render information using type-based labeling.
189+
///
190+
/// This type-safe variant of `debugScan` derives the debug label from the specified view type, providing
191+
/// a more robust and refactor-friendly approach to view debugging. The modifier logs details such as the file,
192+
/// module, redraw count, and timestamp for each render pass, using the view's type name as the identifier.
193+
///
194+
/// - Important: For the best logging experience, it is recommended to apply this modifier to **root views**
195+
/// (e.g., the top-level view in your view hierarchy) rather than leaf views. Applying it to root views ensures
196+
/// that you capture the most meaningful and comprehensive debug information.
197+
///
198+
/// - Parameters:
199+
/// - label: The type to use for generating the debug label. The label will be generated using `String(describing: label)`.
200+
/// Pass the view's type (e.g., `Text.self`, `MyCustomView.self`) to get meaningful debug labels.
201+
/// - file: The file where the view is defined. Defaults to the current file (`#file`).
202+
/// - fileID: The file ID where the view is defined. Defaults to the current file ID (`#fileID`).
203+
/// - filePath: The full file path where the view is defined. Defaults to the current file path (`#filePath`).
204+
///
205+
/// - Returns: A modified view with debug instrumentation applied, using the type-derived label.
206+
///
207+
/// - SeeAlso: `debugScan(_:file:fileID:filePath:)` for the string-based variant that allows custom labels.
208+
func debugScan(
209+
_ label: (some View).Type,
210+
file: StaticString = #file,
211+
fileID: StaticString = #fileID,
212+
filePath: StaticString = #filePath
213+
) -> some View {
214+
modifier(
215+
ViewInstrumentationModifier(
216+
label: String(describing: label),
217+
file: file,
218+
fileID: fileID,
219+
filePath: filePath
220+
)
221+
)
222+
}
185223
}

0 commit comments

Comments
 (0)