IOS debugger using NSAssert() and NSParameterAssert

Time:2022-8-8

IOS debugger using NSAssert() and NSParameterAssert

NSAssert:

NSAssert() is just a macro used to debug bugs in the program during the development phase. By passing a conditional expression to NSAssert() to determine whether it is a bug, it returns true if the condition is satisfied, and the program continues to run. If it returns false, it throws Exception, and can customize the exception description. NSAssert() is defined like this:


#define NSAssert(condition, desc)

condition is a conditional expression with a value of YES or NO; desc is an exception description, usually an NSString. When the condition is YES, the program continues to run, and when it is NO, the exception information described by desc is thrown. NSAssert() can appear anywhere in the program.

The following describes NSParameterAssert

Assert evaluates a condition, and if the condition is false, invokes the current thread's breakpoint handle. Each thread has its own breakpoint handle, which is an object of class NSAsserttionHandler. When called, the assertion handler 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 method and class names (or the function name). 
It then raises anNSInternalInconsistencyException exception.

This macro is used to validate the validity of an Objective-C method. Simply provide the parameter as a condition. The macro evaluates this parameter, and if false, it prints an error log message containing 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 includes the parameter and then raises an exception.

Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined. All breakpoint macros return void.


Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined. 
All assertion macros return void.

Thank you for reading, I hope it can help you, thank you for your support to this site!