1. Print and Logger
Logger messages can be filtered in the Xcode console and in the Console app, and they do not slow down release builds.
2. Breakpoints
Click the line number gutter to set a breakpoint. When the app reaches that line it pauses and you can inspect all variables.
| Control | Shortcut | Action |
|---|---|---|
| Continue | Ctrl + Cmd + Y | Run until the next breakpoint |
| Step over | F6 | Run this line |
| Step into | F7 | Go inside the function |
| Step out | F8 | Finish the function |
- Conditional breakpoint: Right-click the breakpoint, choose Edit, set a condition like
index == 42 - Action breakpoint: log a message and continue automatically, without editing code
- Exception breakpoint: Add from the Breakpoint navigator to stop exactly where a crash starts
- Symbolic breakpoint: stop whenever a certain method is called
3. LLDB in the Console
4. View Debugger
While the app runs, click Debug View Hierarchy (the stacked-layers icon). Xcode shows a 3D exploded view of every layer. Use it to find hidden views, wrong sizes or overlapping buttons.
5. Understanding Crashes
| Message | Usual cause |
|---|---|
Unexpectedly found nil while unwrapping an Optional | Used ! on nil |
Index out of range | Array access with a bad index |
Thread 1: Fatal error: No ObservableObject / environment object of type ... found | Forgot to inject a model with .environment(...) |
Unable to simultaneously satisfy constraints | Conflicting Auto Layout rules |
This application is modifying the autolayout engine from a background thread | UI updated off the main thread |
Terminating app due to uncaught exception | Missing Info.plist usage description or an Objective-C error |
6. Memory Leaks: Retain Cycles
To find leaks run the app, open the screen and leave it several times, then click the Debug Memory Graph button. Leaked objects appear with a purple exclamation mark.
7. Instruments
Open Instruments with Product > Profile (Cmd + I). Choose a template:
| Template | Finds |
|---|---|
| Time Profiler | Slow functions that use the CPU |
| Allocations / Leaks | Memory growth and leaks |
| SwiftUI | Views that redraw too often |
| Network | Slow or repeated requests |
| Energy Log | Battery drain |
Conclusion
Debugging is a skill. Use Logger, breakpoints, LLDB, the view debugger, the memory graph and Instruments, in that order of effort.

