Objective-C: Assertion vs. Exception vs. Error

前端 未结 4 1879
南旧
南旧 2020-12-12 10:55

In Cocoa, when should I use NSAssert, NSException, NSError?

Here\'s what I\'ve been thinking:

NSAssert - When creating any client program us

4条回答
  •  粉色の甜心
    2020-12-12 11:26

    Edit: In Xcode 4.2, assertions are turned off by default for release builds,

    Now NSAssert will not be compiled into your code in a release build, but you can change it in build settings


    @Mike Weller, There are one wrong in your answer.

    One thing to note is that NSAssert will not be compiled into your code in a release build, so this is typically used for sanity checking during development.

    Actually, NSAssert will be compiled into your code if you don't add NS_BLOCK_ASSERTIONS in your precompiled prefix files.

    In Technical Note TN2190 we can find:

    Macros like NDEBUG to turn off C assert or NS_BLOCK_ASSERTIONS to turn off Foundation's NSAssert are important to specify for your precompiled prefix files

    Or you can read this one:How to know if NSAssert is disabled in release builds?

提交回复
热议问题