Pedr Pedr - 4 months ago 7
iOS Question

Objective-C preprocessor directive for 'if not'

I understand how to use a preprocessor directive like this:

#if SOME_VARIABLE
// Do something
#else
// Do something else
#endif


But what if I only want to do something IF NOT SOME_VARIABLE.

Obviously I still could do this:

#if SOME_VARIABLE

#else
// Do something else
#endif


. . . leaving the if empty, But is there a way to do:

#if not SOME_VARIABLE
// Do something
#endif


Apple documentation here suggests not, but this seems like a very basic need.

Basically I want to do the preprocessor equivalent of:

if(!SOME_VARIABLE)(
{
// Do Something
}

Answer

you could try:

#if !(SOME_VARIABLE)
   // Do something
#endif
Comments