|
6 | 6 | [](https://github.com/apple/swift-package-manager) |
7 | 7 | [](https://github.com/ConsultingMD/swift-ui-debug-scan) |
8 | 8 |
|
9 | | -A Swift package designed to enhance your debugging experience with SwiftUI views by providing detailed and structured debug logging. |
| 9 | +**Enhanced SwiftUI debugging with structured view insights and render tracking.** |
10 | 10 |
|
11 | | - |
12 | | -## Why use swift-ui-debug-scan? |
13 | | - |
14 | | -Debugging SwiftUI can often feel like navigating a maze, especially when trying to trace metadata such as the file a view belongs to, the module it was declared in, or how often it gets redrawn. This lack of visibility can be particularly challenging in large, server-driven UI applications where static data is sparse, and the codebase is unfamiliar. |
15 | | - |
16 | | -swift-ui-debug-scan bridges this gap by offering structured, actionable insights into your SwiftUI views. With this tool, you can easily track view metadata, redraw counts, and other runtime information, making it easier to debug and optimize your SwiftUI applications. |
17 | | - |
18 | | - |
19 | | -## How it Works |
20 | | - |
21 | | -The `.debugScan(_ label: String)` view modifier is the core of this library. By applying this modifier to your SwiftUI views, you can log structured debug information about the view's lifecycle and runtime behavior. |
| 11 | +## Quick Start |
22 | 12 |
|
23 | 13 | ```swift |
24 | 14 | import SwiftUI |
25 | 15 | import SwiftUIDebugScan |
26 | 16 |
|
27 | 17 | struct ContentView: View { |
28 | 18 | var body: some View { |
29 | | - Text("Some feature").debugScan("Content") |
| 19 | + Text("Hello World").debugScan("MainView") |
30 | 20 | } |
31 | 21 | } |
32 | 22 | ``` |
33 | 23 |
|
34 | | -## Sample Debug Output |
35 | | - |
36 | | -When running your app in debug mode, you'll see logs like the following in the console: |
37 | | - |
| 24 | +**Console Output:** |
38 | 25 | ``` |
39 | | -🧩 [Content] |
| 26 | +🧩 [MainView] |
40 | 27 | • 📂 file: ContentView.swift |
41 | 28 | • 📚 module: MyApp |
42 | 29 | • 🎨 redraws: 1 |
43 | 30 | • ⏱️ timestamp: 2025-07-21 14:05:40 +0000 |
44 | 31 | ``` |
45 | 32 |
|
46 | | -## When to use `.debugScan`? |
| 33 | +## Why Use This? |
47 | 34 |
|
48 | | -Apply the `.debugScan(_ label: String)` modifier to root views rather than leaf views. This ensures you capture meaningful data about the overall structure and behavior of your app without overwhelming your logs with excessive detail. |
| 35 | +- 🔍 **View Metadata**: Track file, module, and render counts |
| 36 | +- 🐛 **Debug Complex UIs**: Essential for large, server-driven applications |
| 37 | +- ⚡ **Performance Insights**: Identify over-rendering and optimization opportunities |
| 38 | +- 🎯 **Targeted Debugging**: Focus on root views without log noise |
49 | 39 |
|
50 | | -For example: |
51 | 40 |
|
52 | | -- Use `.debugScan(_ label: String)` on the root view of a screen or a major container view. |
53 | | -- Avoid applying it to small, frequently updated views unless necessary. |
| 41 | +## Usage Best Practices |
| 42 | + |
| 43 | +**✅ Apply to root views:** |
| 44 | +```swift |
| 45 | +NavigationView { |
| 46 | + HomeScreen() |
| 47 | +}.debugScan("HomeNavigation") |
| 48 | +``` |
54 | 49 |
|
55 | | -## Verbose Mode |
| 50 | +**❌ Avoid on leaf views:** |
| 51 | +```swift |
| 52 | +// Don't do this - too much noise |
| 53 | +Text("Button").debugScan("ButtonText") |
| 54 | +``` |
56 | 55 |
|
57 | | -For even more detailed logging, enable verbose mode by setting the `SWIFTUI_DEBUG_SCAN_VERBOSE` environment variable to true, yes, or 1. This will include additional runtime information such as: |
| 56 | +**💡 Recommended targets:** |
| 57 | +- Screen root views |
| 58 | +- Major container views |
| 59 | +- Complex custom components |
| 60 | +- Views with performance concerns |
58 | 61 |
|
59 | | -- Call stack symbols |
60 | | -- Thread details |
61 | | -- System memory and processor usage |
62 | | -- Uptime and elapsed time |
| 62 | +## Advanced Features |
63 | 63 |
|
64 | | -Verbose mode is especially useful for diagnosing complex issues in large applications. |
| 64 | +### Verbose Mode |
| 65 | +Set `SWIFTUI_DEBUG_SCAN_VERBOSE=1` for detailed diagnostics: |
| 66 | +- 🧵 Call stack and thread info |
| 67 | +- 💾 Memory and CPU usage |
| 68 | +- ⏱️ Performance timing |
| 69 | +- 📊 System metrics |
65 | 70 |
|
66 | 71 | ## Installation |
67 | 72 |
|
68 | | -Add this package to your project using Swift Package Manager: |
69 | | - |
| 73 | +**Swift Package Manager:** |
70 | 74 | ```swift |
71 | 75 | dependencies: [ |
72 | 76 | .package(url: "https://github.com/ConsultingMD/swift-ui-debug-scan", from: "0.1.0") |
73 | 77 | ] |
74 | 78 | ``` |
75 | 79 |
|
76 | | -Then add the dependency to your target: |
77 | | - |
78 | | -```swift |
79 | | -.target( |
80 | | - name: "YourTarget", |
81 | | - dependencies: [ |
82 | | - .product(name: "SwiftUIDebugScan", package: "swift-ui-debug-scan") |
83 | | - ] |
84 | | -) |
85 | | -``` |
86 | | - |
87 | | -Alternatively, you can add the package directly in Xcode: |
88 | | - |
89 | | -1. Open your project in Xcode. |
90 | | -2. Navigate to `File > Add Packages`. |
91 | | -3. Enter the repository URL: `https://github.com/ConsultingMD/swift-ui-debug-scan`. |
92 | | -4. Choose the version or branch you want to use. |
93 | | -5. Add the package to your desired target. |
| 80 | +**Xcode:** `File > Add Packages` → Enter URL above |
94 | 81 |
|
95 | 82 | ## Contributing |
96 | 83 |
|
97 | | -Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to open an issue or submit a pull request. |
| 84 | +Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 85 | + |
| 86 | +**Quick fixes:** Fork → Change → Test → PR |
| 87 | +**New features:** Open issue first to discuss |
0 commit comments