在开发过程当中,往往会输出一些内容来debug程序,系统的NSLog虽然好用,但如果输出过多时会让你头痛,你根本不知道是在程序的哪儿输出的。于是我们有必要输出更多的信息来标识。下面是一个宏,大家可以参考。
// 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__);
用DLog代替NSLog,在Debug模式下就会输出信息,包括方法名,行数及你想要输出的内容。ALog无论在Debug还是在Release模式下都会输出。
需要defineDEBUG, 下面有张图,一目了然。