[英]Print out the variable name objective-C
Continued from the last question here: Log method name in Obj-C . 继续上一个问题: 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__])
#define logIntVariable(x) NSLog( @"Value of %s = %d",#x, x)
- (void) myRoutine {
int intValue = 5;
logIntVariable(intValue);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.