在发布应用程序之前是否需要禁用NSLog? [英] Do I need to disable NSLog before release Application?

查看:75
本文介绍了在发布应用程序之前是否需要禁用NSLog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为iPhone发布应用时,如果我禁用 NSLog(); 它会表现更好吗?

When releasing an app for iPhone, if I disable NSLog(); will it perform better?

推荐答案

一种方法是进入Build设置并在Debug配置下为Preprocessor Macros值添加一个值,如:

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

确保只执行此操作用于Debug配置,而不用于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

现在代替 NSLog 在任何地方使用 DLog 。在测试和调试时,您将获得调试消息。当您准备发布测试版或最终版时,所有 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屋!

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