Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code loses syntax color in Xcode 4

I have just upgraded to the new Xcode 4 and the code is not colored has it ought to be.

For instance, the string NSString is not colored in my custom code, but when I switch to Apple's code (NSString.h for example) everything is well colored.

How can I fix that?

like image 774
MartinMoizard Avatar asked Mar 13 '11 10:03

MartinMoizard


4 Answers

It's a known bug with the latest XCode. This happens with some projects which are migrated from XCode 3.X to the new version. For some people it seems to help to go to the organizer, and in the project tab delete the derived data for the project where code sense does not work correctly.

If you have a small project, it might also help to create a new project in XCode 4 and import the files from the XCode 3 project.

Update: XCode 4.0.1 made the situation a bit better, at least in some of my projects I have syntax coloring and code sense back. But it's still far from fixed.

Update 2: XCode 4.0.2 did not change much. It seems that the problem is related to subprojects, specifically static libraries. According to comments of this blog post some people were successful by changing header search paths from relative to absolute paths, e.g. instead of Foo/Bar use $(SOURCE_ROOT)/Foo/Bar. This together with switching all projects to XCode 3.1 format and to use LLVM 2.0 fixed a lot for me as well. It's not perfect yet, but usable.

Update 3: After converting the sub projects to independent projects and putting them in a workspace (aka the XCode 4 way) I have now full syntax highlighting and code completion back.

My current environment is now a XCode 4 workspace with each projects being 3.1 compatible (as opposed to the default which is 3.2), LLVM GCC 4.2 (system default) and the header search paths are still absolute (using $(SOURCE_ROOT)/.../).

like image 66
Alfonso Avatar answered Jan 02 '23 20:01

Alfonso


I used undefined Macro, But those macros defined in Preprocessor Macros in build settings. So the xcode4 didn't generate any error for that undefined macro.

Steps taken to resolve.

  1. Removed undefined macros wherever I used those undefined macros.
  2. Removed duplicate definitions of Marcos.
  3. Removed duplicate Resources. (I'd added same (many Thumbs.db files) files into the project.)
  4. Clean & Build.

if still you are not getting the color then, please relocate your project to some different location, I changed to my Desktop location.

After these steps I got the color in my eyes.

But its very bad issue. I sucks lot of valuable time. I think these steps may help you.

Thanks.

like image 43
Jeevanantham Balusamy Avatar answered Jan 02 '23 19:01

Jeevanantham Balusamy


I had the same problem with mine. Its a cocos2d game with box and chipmunk. It was a hell of a mess getting the project to recognize and find the user search paths in the first place so I wasn't about to mess with those.

What I wanted to point out is that I DO HAVE recursive paths and I do have relative paths and I still got the issue. It happened when I added a new version of a 3rd party SDK I was using. It was Testflight 083 which I updagraded to 1.0. I erased my old version but only removed references. Then I manually deleted it from finder. Imported the new SDKv1 folder and readded it to my project and removed the old SDK0 folder path leaving only the newly added SDK1 folder path. For some reason I noticed that even though in v083 I had used a #import in my Prefix.pch file, it still wasn't recognizing a call to a method from AppDelegate. Which means the #import in Prefix.pch for some reason was not working. I had to add #import to my AppDelegate file individually. This gave me duplicate #imports as Jeeva said above. That sounded an alarm in my head.

So the solution was to go and effectively remove the duplicate #import in Prefix.pch therefore only leaving the one in AppDelegate. It reindexed and CodeSense works again. Thanks Jeeva!

like image 34
marciokoko Avatar answered Jan 02 '23 20:01

marciokoko


This issue was driving me insane, and I had given up hope of fixing it without some ugly hack on XCode's configuration. I passed through this very forum thread a stack overflow of times. Then one day, I happened to accidentally fix it. I'm not sure if you need all these steps, but I've found this a sure-fire way to fix XCode's indexing issues:

  • Clean your project (Command-shift-K)
  • Open organizer, close your project.
  • Under the "Projects" tab in organizer, remove the derived data for the project you want to reset.
  • Quit XCode
  • In the terminal, run:

    sudo mdutil -a -i on
    

    This seems to reset spotlight indexing (I don't know much about it because I don't use spotlight).

  • When the command finishes, Spotlight will have to re-index. Look up to see a little dot in the magnifying glass for your spotlight's icon. When the dot leaves, spotlight has re-indexed. You can check the progress by opening spotlight.
  • Re-open XCode, and wait for it to re-index all your files.
  • Build the project.

On build success, you should now have appropriate syntax highlighting again. I hope you guys find this little discovery as useful as I did :)

EDIT:

I should probably add that the syntax highlighting sometimes seems to re-break when the debugger hangs the simulator during app launch. I just try to avoid this by being more careful about letting the process hang.

EDIT2: (sorry first contribution)

Works on XCode 4.6 and 4.6.2.

like image 38
creativeandre Avatar answered Jan 02 '23 21:01

creativeandre