Print out the variable name objective-C
Posted
by vodkhang
on Stack Overflow
See other posts from Stack Overflow
or by vodkhang
Published on 2010-05-12T12:01:14Z
Indexed on
2010/05/12
12:04 UTC
Read the original article
Hit count: 221
Continued from the last question here: Log method name in Obj-C . I just wondered if there is a way to print out the variable name as well. For example:
NSString *name = "vodkhang";
NCLog(@"%@", name);
and I hope that the output should be:
name: vodkhang
Just to summarize the previous post, currently, I can print out the class name, method name and the line number when I call
NCLog(@"Hello World");
<ApplicationDelegate:applicationDidFinishLaunching:10>Hello world
with
#define NCLog(s, ...) NSLog(@"<%@:%d> %@", __FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
© Stack Overflow or respective owner