Generates an assertion if a given condition is false.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
An expression that evaluates to
NSStringobject that contains a
printf-style string containing an error message describing the failure condition and placeholders for the arguments.
The arguments displayed in 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
NSAssertion. When invoked, an assertion handler prints an error message that includes the method and class names (or the function name). It then raises an
NSInternal exception. If
condition evaluates to
NO, the macro invokes
handle 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 is defined or the
ENABLE Xcode build setting is disabled.