NSAssert
Apple在Foundation.framework中定义了这样一个宏:
#define NSAssert(condition, desc, …)
- 注:第一个参数
condition
为条件判断,若为false,则抛出异常,并显示第二个参数desc
所描述的信息。
Example
NSAssert(1 > 2, @"1 > 2 is false!");
-
在debug模式下运行,会终止程序,并抛出如下异常:
2015-11-04 11:01:16.618 NSAssertTest[825:c07] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘“1 > 2 is false!
-
在release模式下运行,程序不终止也不抛出异常。
总结:合理使用NSAssert
可以有效调试程序。