How to print string value from breakpoint action in Xcode 4?

Here is a solution using only one action, and using fewer characters than the expr solution.

debugger command using NSlog

However, unless you add the void like this:

po (void)NSLog(@"the person name is: %@", p.name)

you will get an annoying "nil" printed out with your log. for example:

(lldb) po NSLog(@"foo")
 nil
2013-06-19 14:42:59.025 TheMove[95864:c07] foo

(lldb) po (void)NSLog(@"foo")
2013-06-19 14:43:10.758 TheMove[95864:c07] foo

If you can live with the nil (I can) it's faster to type and easier to remember just the po


There are a couple of things you can do. Add a Log function from the drop-down, then add another box and select Debugger Command and enter po f.name.

If you want your log to be more complicated, you could do something more like this:

the person name is: @(const char *)[(NSString*)[p.name description] UTF8String]@

You best bet is probably to just use the debugger's graphical interface to watch variables. If you want to log messages, use NSLog.


You can use NSLog statements with breakpoints using "Debugger Command", but you need to add "expr"

expr (void)NSLog(@"The Person Name is %@", p.name)

-

using expr command with a Debugger Command as breakpoint in Xcode 4.4