我需要在发布应用程序之前禁用 NSLog 吗? [英] Do I need to disable NSLog before release Application?
问题描述
发布 iPhone 应用程序时,如果禁用 NSLog();
性能会更好吗?
When releasing an app for iPhone, if I disable NSLog();
will it perform better?
推荐答案
一种方法是进入您的构建设置,并在调试配置下向预处理器宏"值添加一个值,例如:
One way to do it is to go into your Build settings and under the Debug configuration add a value to "Preprocessor Macros" value like:
DEBUG_MODE=1
确保您只对调试配置执行此操作,而不是对 Beta 或 Release 版本执行此操作.然后在通用头文件中,您可以执行以下操作:
Make sure you only do this for the Debug configuration and not for Beta or Release versions. Then in a common header file you can do something like:
#ifdef DEBUG_MODE
#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... )
#endif
现在到处使用 DLog
而不是 NSLog
.在测试和调试时,您将收到调试消息.当您准备发布 Beta 版或最终版时,所有这些 DLog
行会自动变为空,并且不会发出任何内容.这样就不需要手动设置变量或注释 NSLogs
.选择您的构建目标即可解决问题.
Now instead of NSLog
use DLog
everywhere. When testing and debugging, you'll get debug messages. When you're ready to release a beta or final release, all those DLog
lines automatically become empty and nothing gets emitted. This way there's no manual setting of variables or commenting of NSLogs
required. Picking your build target takes care of it.
这篇关于我需要在发布应用程序之前禁用 NSLog 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!