Objective-C 相当于 if(D)Log.w(TAG,“Message”)
在我的 Android 程序中,我经常使用:
private static final boolean D = true;
然后我对 Log 的所有调用都以 if(D) 开头,
if(D)Log.w("Tag", "message");
这有助于通过将 D 值设置为 false 以删除所有日志记录来轻松清理代码。
2个问题: 在目标 C 中调用“NSLog”是否有任何发布产品开销?
上面的 if(D) 逻辑的最佳等价物是什么?
现在我正在尝试
#ifdef macro
NSLog(@"%@",@"Some debug info");
#endif
这是否会从编译单元中删除有问题的代码?
谢谢你!
In my Android programs, I frequently used :
private static final boolean D = true;
Then all of my calls to Log were prepended with if(D)
if(D)Log.w("Tag", "message");
This helped easily clean up code by setting the D value to false to remove all logging.
2 Questions:
Do calls to "NSLog" in objective C have any release product overhead?
What would be the best equivalent of the if(D) logic above?
Right now I'm trying the
#ifdef macro
NSLog(@"%@",@"Some debug info");
#endif
Does this remove the code in question from the compilation unit?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,调用
NSLog
会产生开销。每个调用都是一个函数调用,它格式化字符串并将其写入某处。是的,如果未定义
宏
,则#ifdef宏
会完全删除NSLog
调用。但是,执行以下操作可能会更简单:
并使用
D_NSLog
代替NSLog
。Yes, calls to
NSLog
have overhead. Every call is a function call that formats a string and writes it somewhere.Yes, the
#ifdef macro
removes theNSLog
call entirely, ifmacro
is not defined.However, it might be simpler for you to do something like this:
and use
D_NSLog
in place ofNSLog
.我在这里的错误/误解,我认为他所说的意思是如果他必须调用NSLog
没有任何发布产品开销。release
无论是否。最好的等价物可能是:
或者:
无论哪种方式都有效......如果我正确理解你的问题。
My fault/misconception here, I thought that by what he said he meant if he had to callNSLog
does not have any release product overhead.release
on it or not.The best equivalent would probably be:
alernatively:
whichever way will work... if I understand your question correctly.