美文网首页
assert和NSAssert

assert和NSAssert

作者: Alfred_小乐 | 来源:发表于2016-09-01 16:51 被阅读754次

assert断言,assert(表达式),表达式为真,什么也不做,表达式为假则crash。

assert在OC里面是一个宏,用法一样,只有在Debug状态下有作用。

NSAssert和assert一样也是一个宏,用法也差不多,只是多了在让程序crash时可以报自定义的log异常,这个也是只在Debug状态下有用

在app中加入一行代码

NSAssert(0, @"哈哈哈哈");

Debug状态下app崩溃

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '哈哈哈哈'

*** First throw call stack:

(

0  CoreFoundation                      0x00000001096d8d85 __exceptionPreprocess + 165

1  libobjc.A.dylib                    0x000000010914cdeb objc_exception_throw + 48

2  CoreFoundation                      0x00000001096d8bea +[NSException raise:format:arguments:] + 106

3  Foundation                          0x0000000108d96d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198

4  ZhuoYu                              0x0000000108c21ea8 -[HomeViewController viewDidLoad] + 520

5  UIKit                              0x0000000109c29984 -[UIViewController loadViewIfRequired] + 1198

6  UIKit                              0x0000000109c6dfae -[UINavigationController _layoutViewController:] + 54

7  UIKit                              0x0000000109c6e882 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462

8  UIKit                              0x0000000109c6e9f4 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126

9  UIKit                              0x0000000109c6fc4d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890

10  UIKit                              0x0000000109c70d0b -[UINavigationController __viewWillLayoutSubviews] + 57

11  UIKit                              0x0000000109e1f503 -[UILayoutContainerView layoutSubviews] + 248

12  UIKit                              0x0000000109b49980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703

13  QuartzCore                          0x000000010db70c00 -[CALayer layoutSublayers] + 146

14  QuartzCore                          0x000000010db6508e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366

15  QuartzCore                          0x000000010db64f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24

16  QuartzCore                          0x000000010db593c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277

17  QuartzCore                          0x000000010db87086 _ZN2CA11Transaction6commitEv + 486

18  QuartzCore                          0x000000010db877f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92

19  CoreFoundation                      0x00000001095fdc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23

20  CoreFoundation                      0x00000001095fdba7 __CFRunLoopDoObservers + 391

21  CoreFoundation                      0x00000001095f311c CFRunLoopRunSpecific + 524

22  UIKit                              0x0000000109a89f21 -[UIApplication _run] + 402

23  UIKit                              0x0000000109a8ef09 UIApplicationMain + 171

24  ZhuoYu                              0x0000000108c21c7f main + 111

25  libdyld.dylib                      0x000000010beb292d start + 1

)

release状态下,运行正常。

相关文章

  • 断言NSAssert

    NSAssert与assert NSAssert和assert是断言,主要的差别是assert在断言失败的时候只是...

  • NSAssert断言

    NSAssert与assert NSAssert和assert是断言,主要的差别是assert在断言失败的时候只是...

  • assert和NSAssert

    assert断言,assert(表达式),表达式为真,什么也不做,表达式为假则crash。 assert在OC里面...

  • NSAssert知识

    assert 是C里面的宏。用于断言。 NSAssert 类似于NSLog(),方便易用。但她只能在Objecti...

  • HQ移动20170317期周报

    1. NSAssert() 和 NSCAssert()的使用 NSAssert()用于 OC 语法的断言NSCAs...

  • iOS断言(NSAssert)的用法

    NSAssert()介绍 NSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()...

  • 使用NSAssert()和NSParameterAssert调试

    NSAssert: NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递...

  • NSAssert和NSParameterAssert

    NSAssert和NSParameterAssert在开发环境中经常被使用,调试和验证代码参数的完整性,断言为真,...

  • nodejs的一些方法

    assert assert.deepEqual()和assert.equal()有点区别! 一开时我们需要这么做:...

  • AVPlayer相关笔记

    1.NSAssert NSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递...

网友评论

      本文标题:assert和NSAssert

      本文链接:https://www.haomeiwen.com/subject/gmthettx.html