Skip to content
项目

关于

用于可视化渲染结果、布局和测量值的 SwiftUI 调试工具包。

开发工具

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+1
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文
Loupe Icon

Loupe

A SwiftUI debugging toolkit for visualizing renders, layouts, and measurements.

Swift 6.0+ iOS 17+ macOS 14+ tvOS 17+ watchOS 10+ visionOS 1+

Overview

Loupe provides runtime debugging tools for SwiftUI applications. Visualize render cycles, inspect layout bounds, track positions, and overlay precision grids—all with minimal setup and zero impact on production builds.

Render Debugging

  • .debugRender() - Visualize when views re-render with colored backgrounds
  • .debugCompute() - Visualize when views re-initialize with red flashes
  • RenderCheck - Batch debugging wrapper for multiple views

Layout Inspection

  • VisualLayoutGuide - Display bounds, safe area insets, and dimensions
  • DraggablePositionView - Track coordinates with draggable overlays
  • VisualGridGuide - Overlay precision alignment grids

Container Shapes (iOS 26+)

  • VisualCornerInsetGuide - Visualize ConcentricRectangle and container shapes

Installation

dependencies: [
    .package(url: "https://github.com/Aeastr/Loupe.git", from: "1.0.0")
]
import Loupe

Usage

Render Debugging

See when views re-render or re-compute:

Text("Count: \(count)")
    .debugRender()      // Shows re-renders with colored backgrounds
    .debugCompute()     // Shows re-computations with red flashes

Batch debug multiple views:

RenderCheck {
    Text("A")
    Text("B")
    Text("C")
}

Full documentation →

Layout Inspection

Display bounds, safe area insets, and dimensions:

ZStack {
    Color.blue
        .overlay {
            VisualLayoutGuide("Content Area")
        }
}

Enable dragging and persistence:

VisualLayoutGuide("Debug View")
    .visualLayoutGuideInteractions(dragEnabled: true, persistenceEnabled: true)

Full documentation →

Position Tracking

Monitor coordinates with draggable overlays:

DraggablePositionView("Tracker")
    .draggablePositionViewInteractions(dragEnabled: true)

Full documentation →

Grid Overlays

Add precision alignment grids:

VisualGridGuide("8pt Grid", squareSize: 8, fit: .exact)
    .ignoresSafeArea()

Full documentation →

Container Shapes (iOS 26+)

Visualize ConcentricRectangle and container shapes:

VisualCornerInsetGuide("Container Shape")
    .padding(20)
    .containerShape(RoundedRectangle(cornerRadius: 32))

Full documentation →

How It Works

All debugging tools are conditionally compiled with #if DEBUG. They are automatically excluded from release builds—no manual cleanup required, no performance impact in production.

  • debugRender() uses a Canvas that generates a random color on each render
  • debugCompute() uses a LocalRenderManager that triggers a red flash on view initialization
  • VisualLayoutGuide uses onGeometryChange for efficient size/inset tracking with automatic collision detection
  • VisualGridGuide calculates optimal square sizes using GCD for perfect tiling

Contributing

Contributions welcome. Please feel free to submit a Pull Request.

License

MIT. See LICENSE for details.

探索相关项目

加载中…