Breakpoints fun in Xcode

Xcode although every 15 minutes will crash, gives you some nice features related to breakpoints. One of those things is the ability to based on a given condition do something. Imagine that when a  var inside your code is equal to 50, you want to output the result:

  1. Start by adding a breakpoint where you want.
  2. Right click on it -> Edit Breakpoint.
  3. Something like this will show up:

Screen Shot 2013-04-26 at 08.53.09

So, after this, add the following condition:

x == 50

And the respective action that you want to be produce if that given condition happens, in this case we will just output in the console:

p x

(“p x” means print x. While for objects you would say “po x”, being “po” “print object”)

In the end you will have this:

Screen Shot 2013-04-26 at 09.01.00

And the corresponding output:

Screen Shot 2013-04-26 at 09.01.51

You can also add different actions ( the “p x” is just a simple example):

Screen Shot 2013-04-26 at 09.02.46

Finally, you can add multiple actions to be done at the same time and continue evaluation after the breakpoint is reached. The last one, is uber important, if you don’t want to break the natural flow of your manual debugging, but you want to avoid polluting your code with conditional if’s to Log things.

Tagged , , , ,

One thought on “Breakpoints fun in Xcode

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: