Question

Is there any setting to gray out the code which is not active in XCode preferences? Eclipse IDE automatically grays out the inactive branch.

#if 1
    <code 1>
#else
    <code 2>
#endif

For the above code, <code 2> should be grayed out, as it is not active.

Was it helpful?

Solution

Xcode does not have this feature built-in. It may be possible to write an Xcode plugin to accomplish this, but you will face the following problems.

  1. The Xcode plugin API is unsupported and undocumented.
  2. Xcode plugins have to be rewritten for new versions of Xcode
  3. It is actually difficult to determine if code is active or not.

That last point takes some explaining. Let's say you have the following code

#ifndef SOME_UNUSED_DEFINE
    // Some code
#else
    // Some other code
#endif

Usually, the else code will be inactive. However, if the compiler is passed -DSOME_UNUSED_DEFINE, then it is reversed. The ifndef code block is inactive, and the else code is active.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top