debugging with xCode (pt 5) – conditional debugging

Conditional

As you’re debugging your app, it may take in user input, for example, a gift name that’s a string.

Hence, code wise we want to say “if gift.name is equal to ‘xbox'”.

If you want to break whenever this string is equal to say “xbox”, you can do so using conditional debugging.

Edit the breakpoint and at the Condition textbox input the code:

The expression must evaluate to something so we simply cast it to BOOL.

Now, if you were to go back to your app and input xbox into the gift.name textfield, the runtime compiler will break to this line.

set

So now that the user have just entered “xbox”, we reach to this breakpoint. Let’s say we want to set this variable to something else instead, say “ps3”.

You simply add in an Action with the Debugger Command and insert the expression:

Again, we’re telling the debugger this is an expression and thus must evaluate to something. Since its a set command, we just cast it void.

Therefore, we’re basically saying if the user enters a string gift.name that matches “xbox”, we want to change gift.name to “ps3” instead.

debugging5_set_condition

use the code’s setter method to set gift.name to ps3 in Action >> Debugger Command‘s textfield

debugging5_action_after_condition

Now when you start the app and input “xbox”, it’ll jump to that breakpoint. While the program is paused, in your variable section, right click and select “Add Expression”. Put gift.name.

debugging5_evaluate_expression

Then, have the debugger step down 1 line (fn + F6) so that you process the line of code. In your variable section, you will see that our expression gift.name was indeed changed to “ps3”.

debugging5_changed