Xcode Column Breakpoints

Xcode 13 adds column breakpoints which work like a more granular version of line breakpoints. Here’s how you use them.

Setting Breakpoints

Xcode supports many different types of breakpoint but it’s the line breakpoint that I use the most. You set one by clicking in the gutter of the source code editor on the line where you want to break:

Xcode source editor with line breakpoint set

Most of the time that’s all I need, but sometimes it’s not granular enough. The debugger may step in and out of property initializers, getters and other methods before you get to the code you want to check.

What if I want to step into the largerThan method? When the debugger hits the breakpoint it stops at the countries argument of the first method (note how it’s underlined):

Xcode line breakpoint with parameter of first function underlined

To reach the second method I need to step in and out of the countries property initializer and then in and out of the visited method.

Column Breakpoints

Starting with Xcode 13, we can set a column breakpoint directly on the largerThan method. Command-clicking on the symbol shows the code actions menu where you can set a column breakpoint:

Code actions menu with Set Column Breakpoint selected

Xcode shows the breakpoint as a small carat at the column in the source code:

Xcode source editor with a column breakpoint set at largerThan method

You can change the breakpoint in the same ways as a line breakpoint. Click on the breakpoint to enable/disable. Drag it away to delete it. Double-click to edit the breakpoint, add conditions and actions. Control-clicking on the breakpoint shows the breakpoint menu. Xcode also shows the breakpoint in the breakpoint navigator.

When the debugger hits the column breakpoint we are already at the largerThan method:

Column breakpoint with largerThan method underlined

Working With Closures

In the WWDC 2021 video on breakpoints they show an example of column breakpoints working with a complex set of Swift closures. When Xcode hits the breakpoint it allows you to inspect the anonymous parameter of the closure ($0).

I can’t get that to work, at least not with Xcode 13, beta 1 (FB9190264). Maybe I don’t understand how it’s supposed to work (let me know). Here’s an example. I’ve set a column breakpoint on the $0 in the last closure:

Column breakpoint on last closure

When Xcode hits the breakpoint I don’t see any of the closure arguments. The only way I could get it to do something useful was to add a line break:

Closure with a line break in the middle

Now I can inspect and set breakpoint conditions on the $0 argument but having to add line breaks somewhat defeats the point of column breakpoints. Maybe the Xcode team will improve that in a future update.

Further Details