Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.3.0] - 2025-11-17
### Added
- Type-based `debugScan` modifier sibling function for type-safe view debugging
- New overload: `debugScan(_ label: (some View).Type)` that derives labels from Swift types
- Uses `String(describing:)` to automatically generate consistent debug labels from view types
- Provides type-safety and refactor-resilience compared to manual string labels
- Requires explicit type specification (e.g., `Text.self`, `MyCustomView.self`) to avoid Swift type inference issues
- Comprehensive test coverage with 6 additional test cases covering type resolution, custom views, and explicit type specification
- Enhanced documentation for both string-based and type-based `debugScan` variants with cross-references

## [0.2.0] - 2025-10-28
### Added
- Comprehensive test suite with 800+ lines of test code
Expand Down
38 changes: 38 additions & 0 deletions Sources/SwiftUIDebugScan/DebugScan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public extension View {
/// - filePath: The full file path where the view is defined. Defaults to the current file path (`#filePath`).
///
/// - Returns: A modified view with debug instrumentation applied.
///
/// - SeeAlso: `debugScan(_:file:fileID:filePath:)` for the type-based variant that automatically derives labels from view types.
func debugScan(
_ label: String,
file: StaticString = #file,
Expand All @@ -182,4 +184,40 @@ public extension View {
)
)
}

/// Adds a debug instrumentation modifier to the view for logging and tracking render information using type-based labeling.
///
/// This type-safe variant of `debugScan` derives the debug label from the specified view type, providing
/// a more robust and refactor-friendly approach to view debugging. The modifier logs details such as the file,
/// module, redraw count, and timestamp for each render pass, using the view's type name as the identifier.
///
/// - Important: For the best logging experience, it is recommended to apply this modifier to **root views**
/// (e.g., the top-level view in your view hierarchy) rather than leaf views. Applying it to root views ensures
/// that you capture the most meaningful and comprehensive debug information.
///
/// - Parameters:
/// - label: The type to use for generating the debug label. The label will be generated using `String(describing: label)`.
/// Pass the view's type (e.g., `Text.self`, `MyCustomView.self`) to get meaningful debug labels.
/// - file: The file where the view is defined. Defaults to the current file (`#file`).
/// - fileID: The file ID where the view is defined. Defaults to the current file ID (`#fileID`).
/// - filePath: The full file path where the view is defined. Defaults to the current file path (`#filePath`).
///
/// - Returns: A modified view with debug instrumentation applied, using the type-derived label.
///
/// - SeeAlso: `debugScan(_:file:fileID:filePath:)` for the string-based variant that allows custom labels.
func debugScan(
_ label: (some View).Type,
file: StaticString = #file,
fileID: StaticString = #fileID,
filePath: StaticString = #filePath
) -> some View {
modifier(
ViewInstrumentationModifier(
label: String(describing: label),
file: file,
fileID: fileID,
filePath: filePath
)
)
}
}
Loading