Xcode: code loses syntax

I found that in various situations, Objective-C code in Xcode 3.1 (Leopard) may not receive the appropriate syntax coloring after typing or losing the color it had.

This is not just an upgrade issue with new custom characters, but also affects Cocoa frame characters.

Sometimes CMD-a, to select all the text on the code page, will do the coloring (re), sometimes double-clicking on the line to select it will work, sometimes I have to add / remove a space in the character to get this character (re). Restoring or closing / reopening a project may or may not work.

Is this a known issue with Xcode? For something that annoys me so much, I find no detailed discussions of this in SO and other places that I would expect.

And is there any command to force repetition of global syntax?

+78
xcode syntax-highlighting
Jan 26 '10 at 7:38 on
source share
15 answers

1.) Go to Project → Build Settings → Header Search Paths

2.) Add "$ (SRCROOT) / **"

3.) Close and reload the project

4.) Go to Xcode -> Window -> Organizer -> Projects -> $ YourProject -> Delete Derived Data

5.) Wait until Xcode rebuilds all the pointers.




For more information, enable verbose logging:

1.) Increase the Xcode log level in the terminal application: defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

2.) Open Console Application. Search "xcode"

3.) I saw "file not found" errors for the header files mentioned in the pch file (so the fix above)

+145
Oct 06 2018-11-11T00:
source share

I had the same problem with a project that was good in Xcode 3, and for which syntax highlighting and code completion broke in Xcode 4. I needed better than half a day to figure this out, but I found that the following steps will reproduce / fix The problem is 100% for me.

After all of the above solutions were unsuccessful, I tried to create a project from scratch and carefully redraw all the files and folders. Every time I imported a couple of files that I checked, and the syntax highlighting still worked. Even after the last few of them, it's all the same. Then I hit the assembly, which failed because I forgot to include a couple of common header files in the .pch project file that were there in the old project. And then CodeSense broke again.

After further research, we found that if you import a header file, which, in turn, imports the same environment header file as .pch already does, then CodeSense will break. The same setup did not cause any problems in Xcode 3.

Example:

project.pch

#import <Foundation/Foundation.h> #import "projectConfig.h" 

projectConfig.h

 #import <Foundation/Foundation.h> #import "one.h" #import "two.h" 

So, removing completely unnecessary

 #import <Foundation/Foundation.h> 

directive "projectConfig.h" you can fix the selection, and the completion of the code will return for you. If your problem is the same as mine.

+43
May 17 '11 at 15:13
source share

Just select the file that has lost syntax coloring, click "Editor"> "Syntax Coloring"> (select your language (Objective C ++ for ex) instead of "Default"

+12
Apr 16 2018-11-18T00:
source share

I found the best way to restore syntax coloring is to simply exit Xcode and run it again. I could not tell you why, but it works every time.

+5
Aug 07 2018-11-11T00:
source share

I find that the following will often do the trick ...

"Re-select" and "Base SDK" - and "Architecture" - in "Build Settings". (Click on the blue project icon in the upper left corner, while in “browser mode”, aka 1 , then select the project settings and clutter there.

Make sure they all line up / it doesn't hurt to do a little toggly-wogglying up there while you are there ... I know, just mix it a bit. You will notice that xCode has a miniature mini-bar - every time you switch between 64 and 32 bits ... This is usually when I know that code highlighting is dead at night, or if I am good to go.

Often I will have a project that will be highlighted instantly in 32-bit mode, and just sits there in 64 ... Who knows .. Ah, Xcode, you wacky botch.

+3
Apr 04 2018-12-12T00:
source share

Choose your project → Build Settings tab → Apple Language LLVM 5.0 → Precompile Prefix Header in YES. NSLog did not stand out. Xcode 5.0.1 is currently running. Hope it helps =) Thanks @rebelzach

+3
Mar 13 '14 at 5:33
source share

I can confirm the 100% fix for this problem based on the question I asked (and actually answered) as shown in the figure below. One thing I will add is that sometimes these are “weird spaces” that can also contribute to the loss of highlight. Either clean yourself, or use the Goggle Toolbox for Mac Xcode 4 plugin that adds an entry to the Xcode Edit menu called Clean Up Whitespace .

enter image description hereenter image description here

+2
Apr 14 '12 at 19:18
source share

This seems like a similar error from question

I managed to fix this problem by setting the Precompile Prefix Header to No in the build settings.

+2
Jan 24 '13 at 18:23
source share

I recently had a similar problem, all colorings and autocompletion stopped working for the built-in frameworks, my own classes still worked. Someone recommended that I disable "Run Static Analyzer" in the build settings. It's weird, but it worked.

+1
May 05 '10 at 2:00
source share

For me, it was that I renamed my project, and Tests the target was still pointing to the old pch location, but my application target was pointing to the new one.

If your application delegate still has a sense of code, this might be for you. Go to the project, select the “Tests” target search prefix and set it to the equivalent value in the target application.

+1
Jan 11 '13 at
source share

Open the project settings ( Project> Change project settings ), and then click the Rebuild Code Code Index button on the General tab. This recreates the index that Xcode uses for syntax coloring.

This process may take some time for large projects, so you can check the progress in the Activity window ( Window> Activity ).

0
Jan 28
source share

In addition, in Xcode4 there is no button to restore the code index.

0
Mar 24 2018-11-21T00:
source share

I had the same problem and solved this by updating my build settings to use the default system compiler, LLVM GCC 4.2.

There seem to be several factors.

0
Apr 28 2018-11-11T00:
source share

I also experience this problem and tried the solutions "rebuild the index", "restart Xcode", "change the compiler setting to LLVM GCC 4.2". It didn’t help me.

So, I tried to immediately add the following code along with freshly creating the header file.

 #include "header.h" using namespace cocos2d 

Then, the code added earlier in the header file is colored, and it can recognize classes and more.

I used cocos2d-x, so my syntax is based on C ++. I have not tested it with Objective-c yet.

0
Dec 18 '11 at 1:20
source share

For someone else does not know why. Let open with Xcode 8.2 , it should work

0
Jun 06 '17 at 4:26
source share



All Articles