For example:
debug_print(foobar); // prints out: foobar is (hello, world)
debug_print(i * 27); // prints out: i * 27 is 54
in other words, print out the variable or the expression literally first, and then dump its values out.
It doesn’t need to be in this form. It can be called as a string too:
debug_print("foobar"); // prints out: foobar is (hello, world)
debug_print("i * 27"); // prints out: i * 27 is 54
Update: or how can it be written if it is not built in?
You can use the macro
As you can see, the NSLog format string expects a %@ (object), so you need to use a variant for integers:
EDIT:
There is a way to use a single macro and have it work with all types: use @encoding to find the type.
With this, you can use debug_print anywhere with (almost) any type, as long as it’s in the print_debug_format_for_type. The encodings that are passed in (from @encode) can be found here [apple docs], and the formats for the format string can be found here [also apple docs]. As is, this works with any object, c-style string, integer, float, or double expression.
(minor caveat: the ObjC BOOL type is actually a typedef’d char, so if you print_debug a boolean expression it will say it is a 1 or 0. While this works, it also means that if you print_debug a char expression, it will say it is the ascii number of the char. To change this behavior (and break BOOL printing), change case ‘c’ to
return @"%@ is %c".