Breakpoints are a time-tested debugging mechanism, but sometimes bringing your application to a halt will interrupt the very thing you’re debugging. This issue often comes up when creating UI elements that can be pinched, dragged, or rotated. Often, the best way to inspect these events is to hear audio feedback, allowing you to debug without pausing the app or taking your eyes off the screen. In this post, I’ll show how to use Xcode’s breakpoint features that utilize sound.
In this example, I’m debugging the pinch gesture code from a previous post. We’ll start by clicking on the bar to the left of the text to create a breakpoint. From here, we can right-click and select ‘Edit Breakpoint…‘.
Now we should see a menu that looks like this:
On this menu we’ve checked off ‘Automatically continue after evaluating‘. This allows us to use the breakpoint to inject some behavior without pausing the execution of the app.
Pre-Canned Sound Bites
If we press the ‘Add Action‘ button, we’ll get a drop down menu. Select ‘Sound‘ to get a list of sound bites. This sound will play each time the breakpoint is triggered. This is ideal if we just want to know that our line of code is being run.
Sometimes a simple confirmation that your code is running is not enough. We’re debugging this code because we need to examine it in more detail. If we switch the action to ‘Log Message‘ and select ‘Speak message‘, we will get text-to-speech feedback. We can even format the text that will be spoken.
Let’s explore some possible inputs, coupled with the output that they would produce:
“handlePinch:” (the name of the function being evaluated)
“0x1894470” (the memory address of the UIPinchGestureRecognizer object)
@[self percentForPinch:pinch]*100.0f@ percent
“zero percent” (because the gesture has just started)
That’s it for audio-related features, but there are other interesting features in this breakpoints menu. I encourage you to continue to explore this nook of Xcode and learn about all the things you can do with breakpoints.