Q:

In Objective-C and Cocoa, is there a function debug_print(foobar) that will print out variable's name as well as dumping out it value?

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?

A:

You can use the macro
#define debug_print(expr...) NSLog(@"%@ is %@", @#expr, (expr))

As you can see, the NSLog format string expects a %@ (object), so you need to use a variant for integers:
#define debug_printI(expr...) NSLog(@"%@ is %d", @#expr, (expr))

EDIT:
There is a way to use a single macro and have it work with all types: use @encoding to find the type.
NSString *print_debug_format_for_type(const char *encoding) {
switch (encoding[0]) {
    case '@': return @"%@ is %@";
    case '*': return @"%@ is %s";

    case 'f': return @"%@ is %f";
    case 'd': return @"%@ is %f";

    case 'q': return @"%@ is %qi";
    case 'Q': return @"%@ is %qu";

    case 'c':
    case 'i':
    case 's':
    default: return @"%@ is %d";
}
}

#define debug_print(expr...) ({                                 \
typedef __typeof__(expr) t;                                     \
NSLog(print_debug_format_for_type(@encode(t)), @#expr, (expr)); \
})

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".

