是否可以使用NSLog语句提交iPhone应用程序二进制文件?

har*_*alb 7 iphone nslog

我即将提交我的第一个iPhone应用程序.

我已经放了很多NSLog语句来测试和调试应用程序.

所以我的问题是"将NSLog语句保留在源代码中是否可以"

我怀疑nslog语句是否会减慢总执行时间.

谢谢.

Jes*_*and 9

我一直用这个(发现它在某处):

// DLog is almost a drop-in replacement for NSLog to turn off logging for release build
// 
// add -DDEBUG to OTHER_CFLAGS in the build user defined settings
//
// Usage:
//
// 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(__FORMAT__, ...) NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#   define DLog(...) do {} while (0)
#endif
// ALog always displays output regardless of the DEBUG setting
#define ALog(__FORMAT__, ...) NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
Run Code Online (Sandbox Code Playgroud)

来自Facebook的three20项目有更复杂的调试或记录方式.


Jas*_*ien 6

我正在研究的应用程序以前有许多NSLog将调试转储到控制台.我们发现它们在iPhone 3G上严重阻碍了性能.在3GS上,性能受到了惊人的影响,但没有那么多.

我的建议是使用预处理器宏和调试预处理器定义在调试版本中有条件地使用NSLog,而不是在发布版本中.