iOS Dev Nugget 15 Use the debugger to quickly inspect an object


Need to run a code review on your codebase? Hire me

The Xcode debugger is very powerful and in some cases seemingly arcane if you are unfamiliar with it. But there are a few very useful things you should use it for. Set a breakpoint by clicking in the gutter along the desired line of code. When code execution pauses at the breakpoint, and you see the debugger prompt appear (lldb), you can type various commands into it. These 2 are very handy and easy to use:

po <expression evaluating to an object>
print <expression evaluating to a native type>


po [[obj someFunction] anotherFunction]
print i*3

Sometimes you may need to cast to the correct return type to work, e.g.

print (int)i*3

Type help to see more details.

Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No


Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter


View archives of past issues