Edit a variable whilst debugging in Xcode

In Xcode it is easy to view the value of a variable whilst debugging at a break point. But not everyone knows that you can edit a variable value at a break point too.

Take an imaginary class:

And put some data in it:

Edit scalars

Scalar variables can easily be edited by from the Variables View by clicking on them and entering the new value.

Variables View editing scalar values
Variables View editing scalar values

And the Console output:

Edit Strings

Now what happens when you want to edit a reference type?

Editing a reference type
Editing a reference type

Bums, how do I edit that then?

Reference type variables can be edited from the Console with the expr keyword like this:

Alternatively, you can use the p shortcut instead:

Edit NSNumber

I can do NSNumber too then, yes?

Er, no.

You have to do that with a constructor, not a literal:

Oh, one more thing, when editing reference type variables from the Console, remember that the Variables View doesn’t get updated. You might want to do a quick ‘po cat’ from the Console to see your updated values.