iPhone-NSAssert使用
来源:互联网 发布:linux主机监控 编辑:程序博客网 时间:2024/05/16 05:38
开发ios程序时调试的好帮手---NSAssert()函数。而且和NSLog()函数一样简单易用,代码如下: NSAssert(x!=0,@"x must not be zero");
在表达式“x!=0”不成立时,程序就会抛出异常,并显示自定义的消息"x must not be zero",并同时显示出错的文件、代码和调用函数等信息,是一个程序追踪的很好手段。
假设x!=0,不满足要求就提示reason-x must not be zero
assert 是C里面的宏。用于断言。
NSAssert 只能在Objective-c里面使用。是assert的一个扩充。能捕获assert类异常及打印一些
可读的日志。而assert只是让app crash(abort).
参考 : nsassert-vs-assert-which-do-you-use-and-when
The basic difference between an NSAssert and a regular assert is that an NSAssertraises an exception when it fails while an assert just crashes the app. NSAssert also lets you supply fancier error messages and logs them. Practically, I really don't think there's much difference between the two--I can't think of a reason to handle an exception thrown by an assertion. (To split hairs, I think NSAssert usually involves less typing because you don't have to includeassert.h, but that's neither here nor there.)
如果希望在debug是assert(NSAssert)生效。而在release时assert(NSAssert) 不工作。
做下面的设置既可。
debug 和 release 的切换。Xcode -> Product -> Edit Scheme
在工具栏中选择模拟器的地方选择edit scheme即可调出该对话框。发现通过更改下面这个,并不起作用。那位同学谁知道在
bulid setting 里面的设置。麻烦告诉我下 :)
- iPhone-NSAssert使用
- iPhone-NSAssert使用
- iPhone-NSAssert使用
- iPhone-NSAssert使用
- iPhone-NSAssert使用
- iPhone-NSAssert使用
- iPhone-NSAssert
- 使用NSAssert
- NSAssert使用
- NSAssert & assert使用
- (0076) NSAssert的使用
- NSAssert的使用
- NSAssert使用 调试
- 小心使用NSAssert
- NSAssert的使用
- NSAssert的使用
- NSAssert的使用
- NSAssert断言的使用
- 设置ubuntu Android sdk环境变量
- Codeforces Beta Round #34 (Div. 2)——C
- 简要分析蓝牙驱动
- 在C++中实现C#的委托
- jpa的context.xml文件
- iPhone-NSAssert使用
- 百度地图SDK for Android【事件监听】
- VC++实现解析快捷方式
- System.nanoTime (计时工具类)
- 记录我的问题与解决办法_链接
- Working with Blocks - from Apple Documentation
- 男人应该多吃的水果
- does not contain handler parameter named 'method' 异常
- float,double转char值:小数值被舍去