IOS应用发布NSLog的如何注释

1 选择工程的Target -> Build Settings -> Preprocessor Macros.

如图,默认 Debug项,是“DEBUG=1”.

2 在程序中设置全局宏定义

在程序的 ApplicationName-Prefix.pch 文件中,加入如下,很简单

#ifdef DEBUG
#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... ) 
#endif

  

3 这样就设置好了,测试

在任意ViewController.m中写入 

DLog(@"1234");

结果:

2012-07-25 17:09:54.448 xxxx[7094:707] <0x28f790 ViewController.m:(64)> 1234

这样发布的时候DLog就不会有输出了。 

  

原文地址:https://www.cnblogs.com/iosdev/p/2608689.html