A Summary of Useful Debugging Tips and Techniques
Breakpoints Beyond the standard breakpoints, you can also set Exception Breakpoints and Symbolic Breakpoints. Use to jump to the breakpoint manager, then click the button in the bottom-left corner to add one. Exception Breakpoint When an Exception Breakpoint is added, the program will be interrupted every time an exception occurs. This is generally used to catch unknown exceptions, allowing execution to pause right at the point where the exception or crash happens. Symbolic Breakpoint A Symbolic Breakpoint can pause execution whenever a specific function is called. For example, adding as a symbolic breakpoint will cause every view controller to pause when it reaches , which is very helpful for tracing program logic and business flow. I have set keyboard shortcuts and for the breakpoints mentioned above. Debug View Hierarchy allows you to dynamically inspect the current UI state while the app is running, including the view hierarchy, control sizes, and positions — all rendered in a 3D effect. After running the app in debug mode, click the button in the debug toolbar. Xcode will pause the app, just like pressing the button, and display a instead of the code editor. Xcode renders the entire view hierarchy of the app's main window on the canvas, with thin lines (wireframes) indicating the bounds of each view. What you now see is a visual representation of the view stack. Click and drag in the canvas to see the view hierarchy as a 3D model. In the debug navigator on the left, select to see the full list of views in the current UI hierarchy. Note: There are two buttons at the bottom-left of the panel. As shown below, make sure they are not both deselected, otherwise some views will be hidden. The right button controls whether hidden views are shown. There are several buttons below the canvas for inspecting the view hierarchy in detail. You can adjust the spacing between view layers: You can change the display zoom level; resets to normal size. You can hide views from the top or bottom — dragging from the left hides from the bottom up, and dragging from the right hides from the top down: The four buttons below serve the following purposes: - Not entirely clear yet (will update when I figure it out); - Show constraints; - Show content only / show wireframes only / show both; - Toggle between 3D and flat view. Selecting a view in the 3D canvas shows its detailed information in the on the right. For example, the image below shows the text properties of a Label. All of these techniques become even more powerful when combined with LLDB. Reference: Xcode – power of breakpoints