XCode debug 模式与 release 模式的一大重要区别:
debug 模式下,可以方便的进行调试,NSAssert 是暴力调试的一大利器
如果只使用一般的 if() {} 来进行 bug 的拣选的话,会存在一些比较麻烦的因素:
1。在你真正发布程序的时候,需要手动的去找到这些代码并将其注释掉
2。if(){} 和程序逻辑混在一堆,你找起来的时候是很麻烦的!
如果用到了 NSAssert 的话,你仅需要由 debug 转换为 release 模式,
所有的 断言将会被自动禁用掉,你不必再去手动的注释掉之前用来拣选 bug 的代码
省去了找寻的麻烦。同时,拣选bug 的 NSAssert 还在那儿,也方便你日后对程序进行升级~
有没有遇到过这样的情况:
1。有时侯在release模式下运行程序的时候,没有问题~ 切换到 debug 模式下,程序跑不通了
2。有时候在debug 模式下运行程序的时候,没有问题~ 切换到 release 模式下,程序跑不通了
为什么?
情况1的原因我找到一个:
debug模式下会试图将一些对象打印出来的。有些对象能够正常使用,但在打印的时候会出一些问题,导致bug;
情况2的原因也找到一个:
参考我前一篇转载的文章。
I am using NSAssert() calls within an iPhone application and my understanding from the Apple docs is that assertions are not compiled into the code if NS_BLOCK_ASSERTIONS is defined. To turn off assertions, in a header file I declare: #define NS_BLOCK_ASSERTIONS However, the assert code still seems to run. Is there something I am missing here? Thanks John
| |||
feedback
|
If you created your Xcode project based on one of the standard templates, the Cocoa headers (including Try putting Or put | |||||||
|