Give your simulator superpowers

RocketSim: An Essential Developer Tool
as recommended by Apple

Debugging breakpoints as a replacement for prints

Debugging breakpoints in Xcode allows you to replace prints and reuse debugging statements in future debugging sessions. By simply enabling and disabling needed breakpoints you can also get rid of debug levels as often defined in libraries like CocoaLumberjack.

  • Reuse breakpoints by enabling them when needed
  • Use breakpoints to replace print statements
  • Keep your code clean without debugging logs

 

How do you stay current as a Swift developer?

Let me do the hard work and join 19,144 developers that stay up to date using my weekly newsletter:

Using debugging breakpoints

The most simple implementation of debugging breakpoints is by adding a print breakpoint instead of adding a print statement in our code. Instead of the following code:

print("Did add \(content.count) content items to bucket \(bucket.name)")

We create a breakpoint on the line where we want the print to be triggered. By right-clicking the breakpoint and selecting Edit breakpoint... we enter the breakpoint detail view.

The breakpoint menu
The breakpoint menu

In this view, you are able to define the behaviour of the breakpoint once it’s triggered.

Editing a breakpoint
Editing a breakpoint

This will log the following line in your console:

"Did add 2 content items to bucket Photos"

po stands for print object and can be used to print any reachable objects within the context of the breakpoint line. By ticking Automatically continue after evaluating actions you allow the debugger to continue without pausing once the breakpoint is hit.

More advanced debugging with breakpoints

You can do a lot more with debugging breakpoints. A great start is to check out the talk by Paul Hudson “How to debug like a pro” which is available here.

 
Antoine van der Lee

Written by

Antoine van der Lee

iOS Developer since 2010, former Staff iOS Engineer at WeTransfer and currently full-time Indie Developer & Founder at SwiftLee. Writing a new blog post every week related to Swift, iOS and Xcode. Regular speaker and workshop host.

Are you ready to

Turn your side projects into independence?

Learn my proven steps to transform your passion into profit.