我正在做一个有关在 Xcode 中调试的演示文稿,并希望获得有关有效使用 NSLog 的更多信息。
特别是,我有两个问题:
最佳答案
以下是一些我经常使用的关于 NSLog 的有用宏:
#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__)
DLog 宏仅用于在设置了 DEBUG 变量时输出(项目的 cflags中的 -DDEBUG 用于调试配置)。
ALog 将始终输出文本(如常规 NSLog)。
输出(例如 ALog(@"Hello world") )将如下所示:
-[LibraryController awakeFromNib] [Line 364] Hello world
https://stackoverflow.com/questions/969130/