作为一个新手程序员,我发现了NSlog
. 它对调试非常有帮助(与 一起NSZombieEnabled
)。
当它打印出所有这些东西时,我可以看到模拟器上的明显性能受到影响。我不认为我在设备上看到任何这样的打击,但我不确定。
那么,留下所有东西需要花费什么NSLogs
吗?它是否在设备上使用更多内存?还是编译器只是忽略它们,就像我为设备编译时那样做注释?
编辑:
根据来自的建议,这是我实施的rano.
在我的App_Prefix.pch
文件中,我添加了:
// DLog is almost a drop-in replacement for NSLog
// DLog();
// DLog(@"here");
// DLog(@"value: %d", x);
// Unfortunately this doesn't work DLog(aStringVariable); you have to do this instead DLog(@"%@", aStringVariable);
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
然后在我的Project Info
检查器中,对于Debug
配置,在标题下,GCC 4.2 - Preprocessing,
我将值添加DEBUG
到名为的顶部条目中,Preprocessor Macros.
像魅力一样工作 -DLog
当我构建一个Debug
版本并ALog
始终输出时输出。