iOS 断言的运用

NSAssert的使用

 
苹果在foundation.framework中定义了这么一个宏:
#define NSAssert(condition, desc, ...)
 
第一个参数为一个条件判断,如果为假,则抛出异常,显示第二个参数所描述的信息。
 
例如
NSAssert(1>=2, @"1>=2 is false!");
 
在debug模式下运行,会终止程序,并抛出如下异常:
2015-11-18 10:23:16.618 TestAssertion[825:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '1>=2 is false!'
 
在release模式下运行,不终止程序不抛出异常。
这样方便调试程序。
posted @ 2015-11-18 10:24  tongyuling  阅读(335)  评论(0编辑  收藏  举报