Use NSAssert () and NSParameterAssert to debug programs and how to use iosnsassert

Source: Internet
Author: User

Use NSAssert () and NSParameterAssert to debug programs and how to use iosnsassert

NSAssert:

NSAssert () is just a macro used to debug bugs in the program in the development phase. It passes a condition expression for NSAssert () to determine whether it is a Bug, returns the true value if the condition is met, and the program continues to run, if a false value is returned, an exception is thrown and the description of the exception can be customized. NSAssert () is defined as follows:

# Define NSAssert (condition, desc)

Condition is a condition expression with a value of YES or NO. desc is an exception description, typically NSString. When conditon is set to YES, the program continues to run. If it is set to NO, an exception message with the desc description is thrown. NSAssert () can appear in any position of the program.

 

The following describes NSParameterAssert.

An assertion evaluates a condition. If the condition is false, the breakpoint handle of the current thread is called. Each thread has its own breakpoint handle, which is an object of the NSAsserttionHandler class. When called, the assertion handle prints an error message that contains the method name, class name, or function name. Then, it throws an NSInternalInconsistencyException.

Assertions evaluate a condition and, if the condition evaluates to false, call the assertion handler for the current thread, passing it a format string and a variable number of arguments. each thread has its own assertion handler, which is an object of classNSAssertionHandler. when invoked, an assertion handler prints an error message that includes des method and class names (or the function name ). it then raises anNSInternalInconsistencyException exception.

This macro is used to verify the validity of an Objective-C method. Simply provide parameters as conditions. This macro evaluates this parameter. If it is false, it prints an error log that contains the parameter and throws an exception.
This macro validates a parameter for an Objective-C method. simply provide the parameter as the condition argument. the macro evaluates the parameter and, if it is false, it logs an error message that contains des the parameter and then raises an exception.

If the pre-processing macro NS_BLOCK_ASSERTIONS asserted is defined, it will be disabled. All breakpoint macros return void.
Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined. All assertion macros return void.

 

Original article: http://blog.csdn.net/judy_luo/article/details/47290795

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.