What's the point of NSAssert, actually?

后端 未结 10 2039
一个人的身影
一个人的身影 2020-12-04 05:43

I have to ask this, because: The only thing I recognize is, that if the assertion fails, the app crashes. Is that the reason why to use NSAssert? Or what else is the benefit

10条回答
  •  再見小時候
    2020-12-04 06:20

    Assertions are commonly used to enforce the intended use of a particular method or piece of logic. Let's say you were writing a method which calculates the sum of two greater than zero integers. In order to make sure the method was always used as intended you would probably put an assert which tests that condition.

    Short answer: They enforce that your code is used only as intended.

提交回复
热议问题