继续上一个问题:Log method name in Obj-C。我只是想知道是否有办法打印变量名称。例如:
NSString *name = "vodkhang";
NCLog(@"%@", name);
我希望输出应该是:
name: vodkhang
总结一下上一篇文章,目前,我可以在打电话时打印出班级名称,方法名称和行号
NCLog(@"Hello World");
<ApplicationDelegate:applicationDidFinishLaunching:10>Hello world
带
#define NCLog(s, ...) NSLog(@"<%@:%d> %@", __FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
答案 0 :(得分:35)
#define logIntVariable(x) NSLog( @"Value of %s = %d",#x, x)
- (void) myRoutine {
int intValue = 5;
logIntVariable(intValue);
}