Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you hide code based on macro definition?

Tags:

xcode

macros

With VisualStudio/Resharper we get a useful feature which hides code (or turns it to another color) based on macro definition. For example:

#ifdef DEBUG

if(!is_DEBUG_defined)
{
   // Make code gray
   // Or hide it!
}

#endif

Is there any way to have this behaviour in XCode? I noticed that in this case any variable/function defined inside the #ifdef/#endif statements is not available outside in XCode's autocomplete if the macro is not defined but it would be very useful if there was also a visual indication that that code is not actually going to be compiled.

like image 492
Francisco Silva Avatar asked Jan 20 '26 09:01

Francisco Silva


1 Answers

Apparently Xcode already does this - but it's hard to see on some Themes. With the default theme, the source code of non-pre-processed sections is plain black.

Change your theme temporarily to "Dusk" (Xcode->Preferences->Fonts&Colors), and then code of non-pre-processed sections will be in plain white, which is much easier to see.

like image 110
HyBRiD Avatar answered Jan 22 '26 02:01

HyBRiD