Xcode debugging tips and tricks

Setting a breakpoint in Xcode, is as easy as clicking on the line number that you want to pause app execution on.

Sometimes, a simple breakpoint is not enough. For this reason, i’ll give you below an overview of some debugging techniques available to you and how they can help you squash your bugs in less time.

Generic Breakpoints!

Xcode doesn’t provide just breakpoints to add in a specific line of code. You can also use some generic ones, accessed by going to the breakpoint navigator then clicking + in the bottom left corner :

1 — Swift Error Breakpoint

We can use this breakpoint to pause the execution when a swift error is thrown. Sometimes an error might be throw n methods deep in your source code or dependencies, then bubble upwards and upwards until they get handled. Once you enable the swift error breakpoint, Xcode will pause where the error occured.

Turn it on:

  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.

2 — Exception Breakpoint

This breakpoint catches exceptions encountered anywhere in your program. Due to the current transition to Swift, this breakpoint is trivial to setup. We should keep it always enabled.

Turn it on:

  1. Add an Exception Breakpoint
  2. Since this breakpoint is more useful if we use Objective-C, change the Exception value from All to Objective-C.
  3. To get the human readable version of the crash, add a Debugger Command and type po $arg1 into the command area.

3 — Symbolic Breakpoint

Sometimes you want to set a breakpoint in a certain place in the app, but you may not have direct access to the code in question. This is where symbolic breakpoints can save your ass.

It’s verry usefull if you want to setup a breakpoint based on a symbol, like a method or function name, regardless of where that name might appear in the code.

Turn it on:

  1. Add a Symbolic Breakpoint
  2. Enter for example [UIView(UIConstraintBasedLayout) _viewHierarchyUnpreparedForConstraint:] for the Symbol to identify Auto Layout constraint problems.
Like what you read? Give elniño a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.