Using an Xcode breakpoint instead of print(“here”)

At one point or another, I’m sure we’ve all used a print statement to track program execution in the debugger:

Xcode print statement

Until this week, that was my usual approach too. But then I came across a very interesting tip. You can do the exact same thing in Xcode without changing your code at all. Set a break point, control-click it, and then click “Edit Breakpoint…”. You can add your debug message straight into the breakpoint like this:

Xcode breakpoint with log statement

It’s a nice way to clean up your code, and the ability to easily toggle the breakpoints is handy too. Note that “breakpoint” is a bit of a misnomer in this case: because we clicked that checkbox, program execution isn’t interrupted (i.e., there’s no break). Nice!

I picked this up from Rehat Kathuria’s article, “Xcode, supercharged“. Some good tips there, and this one in particular really jumped out at me.

Leave a Reply

Your email address will not be published. Required fields are marked *