@@ -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