Pet*_*erK 7 iphone objective-c nslog
我看过这篇文章:在设备上运行时,NSLog信息会发生什么?
...但是想知道在分发应用程序时NSLog是否存在问题,例如填满内存还是什么?当我测试输入数据与数据库的一致性时,我只对它有兴趣.
原因是我有NSLog来控制何时在模拟器中将数据加载到我的数据库中.我上传时可以删除它,但如果我不需要它会很好吗?
你应该删除它.例如,如果您记录UITableViewCell(in -tableView:cellForRowAtIndexPath:)的内容,它可以在性能上产生很大的不同,特别是在较慢的硬件上.
使用宏将NSLog输出保持在调试模式,但将其从释放模式中删除.可以在以下站点找到一个示例:http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog
我在我的pch文件中使用了一组非常方便的宏.
有关详细信息,请参见http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/.
#ifdef DEBUG
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
#define DLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
#endif
#define ALog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#endif
#define ZAssert(condition, ...) do { if (!(condition)) { ALog(__VA_ARGS__); }} while(0)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1461 次 |
| 最近记录: |