Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"?

like image 274
dontWatchMyProfile Avatar asked Dec 10 '11 23:12

dontWatchMyProfile


2 Answers

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.

like image 164
Joe Avatar answered Oct 05 '22 16:10

Joe


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.

like image 25
0x5f3759df Avatar answered Oct 05 '22 16:10

0x5f3759df