Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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__])
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
381 views
Welcome To Ask or Share your Answers For Others

1 Answer

#define logIntVariable(x) NSLog( @"Value of %s = %d",#x, x)


- (void) myRoutine {
   int intValue = 5;

   logIntVariable(intValue);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...