NSAssert

You can use NSAssert() to debug your code, just like NSLog().

i.e.

NSAssert(X <= 0, @"x must large than zero!");

 

 

If x<=0 return NO , it will throw exception.You can see a message "x must large than zero!", and also other related details.

 

 

调试cocoa程序在程序出错时,不会马上停止。使用宏NSAssert可以让程序出错时马上抛出异常。
在debug情况下,所有NSAssert都会被执行。在release下不希望NSAssert被执行,我们通常在release种将断言设置成禁用。
设置方法:在targets种选择build,选择release。在gcc preprocessing下增加Preprocessor Macros 值为 NS_BLOCK_ASSERTIONS.

你可能感兴趣的:(ios征程)