[转]NSAssert的使用

NSAssert的使用

 
苹果在foundation.framework中定义了这么一个宏:
#define NSAssert(condition, desc, ...)
 
第一个参数为一个条件判断,如果为假,则抛出异常,显示第二个参数所描述的信息。
 
例如
NSAssert(2>=4.4, @"2>=4.4 is false!");
 
在debug模式下运行,会终止程序,并抛出如下异常:
2013-04-24 09:24:16.618 TestAssertion[825:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '2>=4.4 is false!'
 
在release模式下运行,不终止程序不抛出异常。
这样方便调试程序。
原文地址:https://www.cnblogs.com/xuhaoranLeo/p/5012730.html