Xcode: macro breaks completion / selection

From Xcode Docs :

Syntax highlighting, code completion, and all other indexed functions are handled by the LLVM parser. If the compiler knows about the character, so does the Xcode IDE.

but none of these "index-driven functions" work for me when writing code inside the preprocessor directive. Does anyone have a solution for this?

Examples:

When creating with warnings about unused parameters, a ton of warnings is turned on even when this parameter is used. The code in this screenshot is from Apples Reachability.m and has not been changed. Note that syntax highlighting also does not exist:

Warnings

Proper completion inside #if :

Correct code completion

But incorrect termination inside #else :

Invalid code completion

This half works with local variables:

Broken Analysis in UIDeviceOrientationIsPortrait Macro

But it breaks again when calling something declared outside the scope of the current method:

Broken Analysis in UIDeviceOrientationIsPortrait Macro

Another example
Another example

Can someone tell me how (or even if) this can be fixed?

+4
source share
3 answers

It turns out that it was a bug, and now it is fixed in Xcode version 4.3.1 (4E1019).

-1
source

Xcode actually evaluates the conditions in the preprocessor directives and only does the selection / completion of the code inside the current true state. for instance

enter image description here

enter image description here

Syntax highlighting, autocomplete, and warnings (in this case, a warning about a broken variable) do not work in the wrong state.

I opened the question of how to make Xcode do all this on both sides of the condition, but so far no luck.
Xcode syntax highlighting in both #if #else preprocessor conditions

For the record, I do not think this behavior is a mistake. I can imagine cases when it would be extremely unpleasant to get errors in code that will not be compiled. However, it would be nice to be able to edit both sides of these conditions without having to manipulate macro definitions.

+2
source

@chown, I think: "If the compiler knows about the symbol ... just like when building." indicate that the compiler parses the code and fulfills all the conditions of the preprocessor. In this case, the compiler will not notice the use of the variable inside such #ifdef , where the condition is not met.

This also explains why it "works great in #else ."

You can try to use the UNUSED macro, but you have to disable the warning for "Unused Values":

 #define UNUSED(a) a ... -(void)test:(id)argument { UNUSED(argument); #ifdef AAA NSLog(@"arg:%@", argument); #endif } 
+1
source

All Articles