打印变量名称目标C [英] Print out the variable name objective-C

查看:147
本文介绍了打印变量名称目标C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从上一个问题继续: Obj-C中的日志方法名称。我只是想知道是否有一种打印变量名的方法。例如:

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);

,我希望输出应该是:

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);
}

这篇关于打印变量名称目标C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆