Macro

NSAssert

Generates an assertion if a given condition is false.

Declaration

#define NSAssert(condition, desc, ...)

Parameters

condition

An expression that evaluates to YES or NO.

desc

An NSString object that contains a printf-style string containing an error message describing the failure condition and placeholders for the arguments.

...

The arguments displayed in the desc string.

Discussion

The NSAssert macro evaluates the condition and serves as a front end to the assertion handler.

Each thread has its own assertion handler, which is an object of class NSAssertionHandler. When invoked, an assertion handler prints an error message that includes the method and class names (or the function name). It then raises an NSInternalInconsistencyException exception. If condition evaluates to NO, the macro invokes handleFailureInMethod:object:file:lineNumber:description: on the assertion handler for the current thread, passing desc as the description string.

This macro should be used only within Objective-C methods.

Assertions are disabled if the preprocessor macro NS_BLOCK_ASSERTIONS is defined or the ENABLE_NS_ASSERTIONS Xcode build setting is disabled.

See Also

Assertions

NSAssertionHandler

An object that logs an assertion to the console.

NSAssert1

Generates an assertion if a given condition is false.

NSAssert2

Generates an assertion if a given condition is false.

NSAssert3

Generates an assertion if a given condition is false.

NSAssert4

Generates an assertion if a given condition is false.

NSAssert5

Generates an assertion if a given condition is false.

NSCAssert

Generates an assertion if the given condition is false.

NSCAssert1

Generates an assertion if a given condition is false.

NSCAssert2

Generates an assertion if a given condition is false.

NSCAssert3

Generates an assertion if a given condition is false.

NSCAssert4

Generates an assertion if a given condition is false.

NSCAssert5

Generates an assertion if a given condition is false.

NSCParameterAssert

Evaluates the specified parameter.

NSParameterAssert

Validates the specified parameter.