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:
- Start by adding a breakpoint where you want.
- Right click on it -> Edit Breakpoint.
- Something like this will show up:
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” means print x. While for objects you would say “po x”, being “po” “print object”)
In the end you will have this:
And the corresponding output:
You can also add different actions ( the “p x” is just a simple example):
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.