Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: code loses syntax coloring

I find that in various situations Objective-C code in Xcode 3.1 (Leopard) can fail to get appropriate syntax coloring after typing or lose coloring that it had.

This isn't just a "refresh" issue with new custom symbols -- but affects Cocoa framework symbols as well.

Sometimes CMD-a to select all text on the code page will make the coloring (re)appear, sometimes double-clicking on a line to select it will work, sometimes I have to add/delete a space in a symbol to get that symbol to (re)color. Rebuilding, or closing/reopening the project may or may not work.

Is this a known issue with Xcode? For something so annoying to me, I'm not finding the plentiful discussions of it on SO and elsewhere I'd expect.

And is there any command to force global syntax recoloring?

like image 259
ColorMeFamous Avatar asked Jan 26 '10 07:01

ColorMeFamous


4 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 a moment until XCode rebuild all indicies


To get more information activate verbose logging:

1.) Increase Xcode log level in Terminal app: defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

2.) Open Console app. Search for "xcode"

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

like image 124
Lars Schneider Avatar answered Nov 18 '22 09:11

Lars Schneider


I had the same issue with a project that was fine in Xcode 3 and for which the syntax highlighting and code completion has broken in Xcode 4. It took me the better half of the day to figure it out but I found that the following steps will reproduce / fix the issue 100% for me.

After trying all the aforementioned solutions to no avail, I tried creating the project from scratch and reimporting every file and folder painstakingly. Every time I imported a couple of files I checked and syntax highlighting still worked. Even after the last few of them it still did. Then I hit build which failed because I forgot to include a couple of common header files in the project .pch file that were there in the old project. And that was when CodeSense broke again.

After further investigation we found that if you import a header file that in turn imports the same framework header file than the .pch already does, then CodeSense will break. The same setup did not cause any issues 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 by removing the wholly unnecessary

#import <Foundation/Foundation.h>

directive from the 'projectConfig.h' you can fix the highlighting and code completion will come back for you as well. If your issue is the same as mine that is.

like image 43
rage Avatar answered Nov 18 '22 08:11

rage


Just select the file who lost the syntax coloring , press Editor > Syntax Coloring > ( choose your language (Objective c++ for ex) instead of 'Default'

like image 16
Emad Avatar answered Nov 18 '22 10:11

Emad


I have found the best way to regain syntax coloring is just to quit Xcode and re-launch it. I couldn't tell you why, but that works every time.

like image 7
todd412 Avatar answered Nov 18 '22 08:11

todd412