Why does Xcode4 not do any syntax highlighting in conditional compilation blocks?
Asked Answered
C

2

6

Example:

#ifdef FREE_VERSION
    tf.text = @"Free";
    NSLog(@"FREE VERSION");
#else
    tf.text = @"Paid";
    NSLog(@"PAID VERSION");
#endif

The first part looks fine in Xcode.

    tf.text = @"Free";
    NSLog(@"FREE VERSION");

is syntax-highlighted. However, the second part is not:

tf.text = @"Paid";

NSLog(@"PAID VERSION");

Is there a setting like "Don't do syntax highlighting in #else parts of conditional cimpilation code"?

Caravel answered 10/12, 2011 at 23:37 Comment(0)
B
9

XCode will try and determine which preprocessor branch will be taken. The branch that is expected to execute will have syntax highlighting while the other does not.

Battle answered 10/12, 2011 at 23:40 Comment(0)
N
3

Most IDEs including XCode and Visual Studio won't highlight code in (non-taken) conditional blocks because in many cases this would result in errors that don't apply and messed up highlighting. Consider a usage such as

#ifdef __APPLE__
// Do something that uses apple-only headers/functions
#endif
#ifdef _MSVC_VER
// Do something that visual studio recognizes
#endif

for code that runs on multiple platforms. Visual Studio won't have any idea how to highlight Apple function names and XCode won't know what to do about Visual Studio pragmas etc.

Normally answered 10/12, 2011 at 23:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.