Xcode Smart Debugging Tips| iOS Development

Shubhransh Gupta
4 min readApr 3, 2022

--

Setting a breakpoint in Xcode is as easy as clicking on the line number that you want to pause the app execution on. An overview can be found within the breakpoint navigator which shows all activated and disabled breakpoints. The debug bar contains a breakpoint activation button to temporarily disable breakpoints from pausing your app.

The Blue label denotes that the breakpoints are enabled

Tip 1: Using Exception breakpoints

One of the user-defined breakpoints I’ve been using for months now is the exception breakpoint. An exception breakpoint is triggered when a specific type of exception is thrown or caught. Whenever the exception breakpoint would hit I would immediately type in the po $arg1 statement after clicking on objc_exception_throw to get more information about the thrown exception:

Folks! we can easily automate this using a defined action in your breakpoint. Any defined actions will be executed at the moment a breakpoint is hit and can be a valuable way to debug your application.

Tip 2: Using Symbolic breakpoints

Symbolic breakpoints are triggered when a specific method or function is called. It’s very useful if you want to set up a breakpoint based on a symbol, like a method or function name, regardless of where that name might appear in the code. They can be added from the breakpoints navigator:

  1. Add a Symbolic Breakpoint
  2. Enter for example `[UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint:]` for the Symbol to identify Auto Layout constraint problems.

Tip 3: Using Swift Error Breakpoint

We can use this breakpoint to pause the execution when a swift error is thrown. Sometimes an error might be thrown in methods deep in your source code or dependencies, then bubble upward until they get handled.

  1. Add a Swift Error Breakpoint
  2. Type the Error Class Name in the type area to decide if the debugger should pause at a specific type of error.

Tip 4: Use a One-shot breakpoint

A temporary breakpoint that only exists until it's triggered and then automatically deleted. This can be used to activate any other breakpoint after one shot breakpoint has been hit.

breakpoint set — one-shot true — name “-[UILabel setText:]”

Tip 5: Skip execution of code line to ease the debugging

In many cases, we want to save debugging time by skipping some of the code. We can do this by asking the debugger to skip over the code.

  • Drag the grab handle near the breakpoint thread 1(instruction pointer) to the code in which you are interested or
  • Configure the breakpoint to skip the code line by adding an expression
thread jump --by (number of lines to be skipped)

Tip 6: Sharing breakpoints through GIT

It would be better if breakpoints are being shared by your colleagues themselves. Since developing is a team game, hence no one can be 100% sure about every code, Sometimes you find yourself looking at your colleague’s workflow and you realize he has some great and useful defined breakpoints. Instead of asking him about instructions to set up the same breakpoints, you can ask him to share them through GIT.

This will move the breakpoint to its own section with shared breakpoints. This makes it really easy to get an overview of all shared breakpoints.

--

--

Shubhransh Gupta

I write about: 🧩 SwiftUI techniques and best practices 📱 iOS development tips and tricks ⚡️ Optimizing app performance