Adding NDEBUG to the Xcode Release target

Programmers often want to put behavior in programs that only happens for debug builds, like logging or other diagnostics. A common convention in C is to surround your debug-only behavior with “#ifndef NDEBUG … #endif”. The double-negative is ugly, but it’s a widely used convention nonetheless.

Xcode doesn’t use this convention by default, so you need to add “-DNDEBUG” to your Release compiles to turn off the debugging behavior. To do this, Get Info on your project, go to the “Build” tab, select the “Release” target and edit the Preprocessor Macros line like in the following screenshot.

Screenshot showing Xcode project configuration dialog

(Credit: Greg Parker)