6
votes

Since the latest XCode update 8.1 (Build 8B62) I'm having strange problems with syntax highlighting/code completion in connection with preprocessor macros.

They worked just fine with the XCode 8 GM seed which I have been using before the update, but now XCode does not recognize the correct target when selecting a scheme. For example, I'm having a controller static library with 2 targets - one for iOS, the other for Apple Watch. In each I use a macro (APP / WATCH) for platform specific operations. But when I'm in the APP target, Xcode editor highlights code as if it is the WATCH target whereas the actual code for this target has no highlighting nor auto completion. Xcode seems to randomly detect macros from different targets. The compiler on the other hand always detects the right code and works 100% fine, so there's nothing wrong with the code. It's just the editor.

Also when I start up Xcode the code gets highlighted for about a second and then gets all white text again. Removing and readding all schemes didn't work, cleaning and deleting Derived Data also has no effect on this. Anyone having the same problem or even a solution for this?

EDIT: I played around with targets and macros a little and I found that Xcode takes only macro from one target and discards all others, no matter what target is selected. Any help?

2
I'm having the same issue. Any luck finding a solution for this? - Alejandro Cotilla
I'm having the same issue too! Have you found anything? - guidev
Sadly nothing, I will be writing a bug report soon. Guess Apple doesn't recognize this bug by themselves because no one there seems to be using objc any more. - optz
Can confirm this bug is still present in Xcode 8.2.1 (8C1002). Syntax highlighting and code completion picks up the preprocessor macros from the first defined target instead of the active target - marinosb

2 Answers

0
votes

Try "Clean build" first... if that doesn't work then try

In the Preprocessor Macros Not Used in Precompiled Headers there are two subheadings

Preprocessor Macros Not Used in Precompiled Headers
debug +
release +

With a plus appearing beside when you hover over them. Press the plus on both of these and you should get:

Preprocessor Macros Not Used in Precompiled Headers
debug +
Any Architecture | Any SDK
release +
Any Architecture | Any SDK

You don't need to enter anything here after you have pressed +. Once you have added these two extra entries, try another clean build.

0
votes

It was an actual bug in XCode 8. With XCode 9 (as of today, Sep 2017 beta 6), it is finally resolved.