A lightweight, Apple-designed debugging library for SwiftUI that helps you visualize layouts, inspect views, and monitor performance with an elegant bottom sheet interface.
- π¨ Random Colors: Highlight all views with random background colors to visualize layout hierarchy
- π Dimensions: Display width and height overlays on each view
- β‘ Performance Monitor: Real-time FPS and frame time tracking with color-coded indicators
- π Tap to Inspect: Tap any view to see detailed size, position, and frame information
- π Grid & Rulers: Minimalist Apple-style grid overlay with customizable spacing (5px, 8px, 20px)
- β¨οΈ Keyboard Shortcut: Toggle with ββ§D in iOS Simulator
- π Bottom Sheet UI: Beautiful, non-intrusive interface that slides up from the bottom
- π‘οΈ Debug-only: Zero overhead in release builds with
#if DEBUG
Add this to your Package.swift:
dependencies: [
.package(url: "https://github.com/yourusername/SwiftUIDebugTools.git", from: "1.0.0")
]Or in Xcode:
- File β Add Package Dependencies
- Paste the repository URL
- Select version and click "Add Package"
import SwiftUI
import SwiftUIDebugTools
@main
struct YourApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.debugEnvironment() // That's it! All views are automatically debuggable
}
}
}That's all you need! The debug tools automatically detect and work with all views in your app - no additional code changes required.
Press ββ§D (Command + Shift + D) to toggle the debug panel
// Add a button to toggle
Button("Toggle Debug Tools") {
DebugManager.shared.toggle()
}
// Or call from anywhere in your code
DebugManager.shared.toggle()The grid overlay supports three sizes:
- 5px - Fine detail grid for precise alignment
- 8px - Apple's standard 8-point grid system
- 20px - Larger spacing for general layout
Change the grid size from the bottom sheet interface when "Grid & Rulers" is enabled.
Automatically applies semi-transparent random colors to each view, making it easy to visualize layout boundaries and view hierarchy.
Displays width and height measurements directly on each view automatically.
Real-time performance metrics displayed in a compact card:
- FPS: Color-coded (green β₯55, orange β₯30, red <30)
- Frame Time: Milliseconds per frame
Tap any view to see:
- Size (width Γ height)
- Position (x, y coordinates)
- Frame (origin, width, height)
- Timestamp of inspection
Minimalist overlay with:
- Customizable grid spacing (5px, 8px, 20px)
- Top and left rulers with measurements
- Subtle, non-intrusive design
- Every 5th grid line emphasized for easy counting
Check out the example app in the Example folder to see all features in action:
cd Example/DebugToolsExample
open DebugToolsExample.xcodeprojThe example includes:
- Simple and complex layouts
- List and grid examples
- Animation performance testing
- Interactive demonstrations of all debug features
- iOS 15.0+ / macOS 12.0+
- Swift 5.9+
- Xcode 15.0+
SwiftUIDebugTools uses:
- UIKit View Hierarchy Traversal to automatically detect and debug all views
- Transparent Overlay Window for rendering debug visuals without modifying your views
- CADisplayLink for accurate performance monitoring
- #if DEBUG compilation to ensure zero overhead in release builds
- #if targetEnvironment(simulator) for simulator-specific keyboard shortcuts
The main singleton that manages debug state:
public class DebugManager: ObservableObject {
public static let shared: DebugManager
public var isVisible: Bool
public var randomColorsEnabled: Bool
public var showDimensionsEnabled: Bool
public var showPerformanceEnabled: Bool
public var showGridAndRulersEnabled: Bool
public var gridSize: GridSize
public func toggle()
}Enum for grid spacing options:
public enum GridSize: Int, CaseIterable {
case small = 5 // 5px
case medium = 8 // 8px
case large = 20 // 20px
}// Enable debug environment (add to root view) - this is all you need!
func debugEnvironment() -> some View
// Optional: Legacy per-view debugging (no longer required)
func debugView() -> some ViewContributions are welcome! Please feel free to submit a Pull Request.
MIT License - feel free to use this in your projects!
Pau Ballada - @pballada
- Inspired by Apple's design language and Xcode's debugging tools
- Built with SwiftUI's modern declarative syntax
Note: This library is only active in DEBUG builds. All debug code is stripped from release builds, ensuring zero performance impact in production.


