[IPhone] 仅在Debug编译的NSLog
一般在开发的时候,会使用NSLog来输出一些除错讯息到Console视窗
但是如果仅用NSLog的话
首先利用下面代码
- #ifdef DEBUG
- #define DebugLog(log, ...) NSLog(log, ## __VA_ARGS__)
- #undef DebugLog
- #define DebugLog(log) NSLog(log)
- #else
- #define DebugLog(log, ...)
- #undef DebugLog
- #define DebugLog(log) NSLog(log)
- #endif
在Xcode的Project=>Edit Active Target "MyProject" 开启编辑画面
在GCC_PREPROCESSOR_DEFINITIONS中加入DEBUG
如果没有GCC_PREPROCESSOR_DEFINITIONS则自行建立

本文介绍了一种在iOS开发中仅在Debug模式下启用NSLog的方法,通过预处理器定义来控制日志输出,便于开发者在不同的编译配置下进行调试。
406

被折叠的 条评论
为什么被折叠?



