关于Debug下的Log打印问题

     在项目中为了调试经常会用到Log打印,比如打印当前方法__func__, 对象,地址等等,所以项目最后每次运行调试控制台满满的都是打印日志,到release发布的时候,显然不太合适,这里其实可以用一个简单的宏来解决。

1 #ifdef DEBUG
2 
3 #define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )//分别是方法地址,文件名,在文件的第几行,自定义输出内容
4 
5 #else
6 
7 #define DLog(...)
8 
9 #endif

     注意在#else后,也就是release中一开始定义成NSLog(...)会报错: Implicit declaration of function 'DLog' is invalid in C99。

 

原因: Release版本下所定义的DLog就成了一个空函数,在链接的是时候会报错。

参考:  http://stackoverflow.com/questions/29234725/implicit-declaration-of-function-dlog-is-invalid-in-c99

  

原文地址:https://www.cnblogs.com/A--G/p/5219718.html