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模式下运行,不终止程序不抛出异常。
这样方便调试程序。

NSAssert的使用的更多相关文章

  1. iOS-----程序异常处理----- 断言NSAssert()和NSParameterAssert区别和用处

    NSAssert和assert是断言,主要的差别是assert在断言失败的时候只是简单的终止程序,而NSAssert会报告出错误信息并且打印出来.所以尽管的使用NSAssert,可以不去使用asser ...

  2. 使用NSAssert()和NSParameterAssert调试程序

    NSAssert: NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异 ...

  3. iOS 10开发NSAssert(断言)的使用

    断言(NSAssert)的使用 字数1055 阅读3270 评论3 喜欢30 NSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug ...

  4. 小心一些,断言可能让你的造成循环引用NSAssert

    block和self的相互引用造成的循环引用,想必大家都是明白的.上下面的代码(截取部分) __weak typeof(self) weakSelf = self; self.jsBridgeFunc ...

  5. 异常:NSException和NSAssert的简单使用

    //断言 - (void)NSAssert_Test:(NSString *)string{ NSAssert(string == nil, @"string == kong or nil& ...

  6. NSAssert用法

    今天突然发现了一个开发ios程序时调试的好帮手-NSAssert()函数.而且和NSLog()函数一样简单易用,代码如下: NSAssert(x!=0,@"x must not be zer ...

  7. 断言--NSAssert

    NSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异常 ...

  8. 【转】使用断言NSAssert()调试程序错误

    NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...

  9. NSAssert使用摘抄

    #define NSAssert(condition, desc, ...) 只有条件condition满足,才会执行下一个语句,否则输出断言错误. 例如: NSAssert(1 != 2, @&qu ...

随机推荐

  1. 使用cygwin出现syntax error near unexpected token'$'do\r

    直接从csdn复制粘贴的.sh代码,放到cygwin下运行sh的时候出错syntax error near unexpected token'$'do\r 解决方法: 1.下载notepad++ 2. ...

  2. ie11媒体查询以及其他hack

    <!doctype html> <html> <head> <title>IE10/11 Media Query Test</title> ...

  3. php常用函数汇总

    php常用函数汇总   字符串截取:           1.substr('要截取的字符串','从第几个字符开始','到第几个字符结束');             * 截取英文或者数字       ...

  4. word2013 blog test

    测试一:style里的内容能保存吗?: int        read; byte *    buf; int        tries; int        read; byte *    buf ...

  5. hdu 3966 Aragorn's Story 树链剖分 按点

    Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. jQuery 效果 —— 滑动

    jQuery 效果 -- 滑动 1.向下滑动元素 (1)使用slideDown()方法可以用于向下滑动元素 $("button").click(function(){ $(&quo ...

  7. jquery.validate使用 - 2

    jQuery.validate.js API说明 参考http://ideabean.javaeye.comPlugin methods Name Type validate( options ) R ...

  8. hdu 5446 Unknown Treasure 卢卡斯+中国剩余定理

    Unknown Treasure Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  9. Claims Identity

    using System;using System.Collections.Generic;using System.Linq;using System.Security.Claims;using S ...

  10. git的一些常用方法

    1.撤销add但未commit的文件: git rm -r --cached path/file 2.git 撤销commit: 2.1).git log-显示提交的历史 commit ee50348 ...