76

EDIT: This is weird... if I double-click the Recent Projects item for the project in the welcome screen, code sense and coloring works just fine but if I just click Open (bottom right in welcome screen) it doesn't. Opening from File > Recent projects does not work either and neither does double-clicking the .xcodeproj file in Finder.


Code sense for an iPhone OS 3.0 project I have been working on for several months (through different installations/versions of Xcode) is not working any more. For instance, if I do NSString *myString, all code would be black (no coloring, no Option + Double Click, no code completion). Code Sense only "works" for my own classes/methods/properties but not for any of the SDK classes. If I create a new project from scratch I do have all of these working.

I already tried changing the "Base SDK for All Configurations" in this project. I already tried "Rebuild Code Sense Index". I already tried "Clean All Targets".

Documentation in the Preferences is all downloaded and working. For instance, if I select the NSString above and do Right-Click -> Find text in documentation, I get the window with all the reference to the class.

Any ideas will be greatly appreciated.

4
  • I had the similar issue for one project only. Code sense color/completion just work fine for other projects. Did you solved it? Commented Mar 19, 2010 at 5:34
  • kind of... the new sdk update is having no trouble. what i have noticed is that it takes a few seconds for the color parsing to complete
    – mga
    Commented Mar 19, 2010 at 15:52
  • 1
    I lose my auto-completion and the text coloring every time I change a file added in the prefix.pch project file. The answers underneath gave me back the auto-completion and the text coloring but the bug still come back when I change files imported in prefix.pch. Anyone found how to fix this issue ?
    – booker
    Commented Apr 26, 2012 at 23:06
  • As of Xcode 4.4, this problem seems to be a lot better.
    – makdad
    Commented Aug 7, 2012 at 10:52

24 Answers 24

205

In Xcode 4, I haven't been able to find a "Rebuild Code Sense" button either, but if you go to Window -> Organizer, select the Project tab, and click "Delete..." next to the Derived Data folder, it seems to have the same effect. (I got that tip from http://blog.slidetorock.com/xcode-4-code-sense-autocompletion-problems, which indicates that it got it in turn from https://stackoverflow.com/questions/2138047/xcode-code-loses-syntax-coloring - but I don't see it in any of the answers there. Very curious.)

5
  • 4
    I tried restarting xcode, and tried resetting the compiler to/from CGG/LLVM, but niether of those worked. This did the trick for me, thanks!
    – adam.wulf
    Commented Jul 22, 2011 at 18:15
  • 1
    Worked for me in XCode 4 also
    – barfoon
    Commented Oct 2, 2011 at 20:41
  • 1
    This worked, and is a quick and easy fix to an annoying bug. Everyone should try this before they attempt some of the more...creative solutions.
    – Murdock
    Commented Dec 6, 2011 at 1:54
  • Or, you can put xcuserdata in your .gitignore file and just do git clean -dXn. Then, review the correct files will be deleted. Then, git clean -dXf to actually delete them.
    – ma11hew28
    Commented Jan 17, 2012 at 18:57
  • 11
    Even though this works, it happens several times a day! I end up having to delete the derived data maybe 4-6 times a day. Its pretty annoying...
    – scooter133
    Commented Mar 15, 2012 at 2:06
40

Just run in terminal every time when needed

rm -fR ~/Library/Developer/Xcode/DerivedData

Works fine. Highlighting and codesense back to me! Sometime needed Make Clean to back it work.

note: as I see it's remove snapshost and another Xcode4 'features'. But we do not use it :)

2
  • 5
    This is better than the other answers here. And it works without restarting XCode.
    – Shiki
    Commented May 5, 2012 at 0:35
  • 2
    Same here, I just used after about half an hour of searching, and it works! Doesn't even take much work... Commented Jun 26, 2012 at 0:27
38

Syntax coloring is working back after i do the following steps:

  • Go to Organizer > Project > Delete Derived Data from your current project
  • Clean & Build
  • Close & Quit XCode, and reopen the project
  • Syntax coloring becomes well after project reindexing

P.S.

  • LLVM Complier 3.0
  • i used -fno-objc-arc Complier Flags for all 3rd party libraries(e.g. ASIHTTPRequest)
  • My project is created from XCode 4.2
2
  • Worked for me, Xcode 4.3.2. I was screaming because it worked half the time. THANKS!!! Commented Apr 20, 2012 at 20:48
  • First 2 steps worked for me! Thnx! xcode 4.3.2. Upgraded to support new iPad but lost autocomplete on the way.
    – Sunkas
    Commented May 6, 2012 at 13:36
12

I've had the same problem in Xcode 4 and solved it by changing the compiler from GCC 4.2 to LLVM GCC 4.2.

3
  • 2
    Interesting. I changed it LLVM GCC 4.2, got some compile errors, changed it back to Apple LLVM 3.1, and the syntax highlighting is back.
    – kevlar
    Commented Mar 22, 2012 at 2:42
  • Can't compile with LLVM GCC 4.2 as well but the simpliest way to get back the auto-completion is to change to LLVM 4.2 -> try compiling -> back to LLVM 3.1 and I get it back. But anyone found how to avoid this bug ?
    – booker
    Commented Apr 26, 2012 at 23:10
  • I had the same issue in Xcode 5.0.2. None of the other steps on this page worked. I changed the target build options compiler to "Default compiler (Apple LLVM 5.0)", even though the option was already set as "Apple LLVM 5.0". I had to specifically select the default option and it fixed it for me instantly. Commented Feb 27, 2014 at 17:30
11

Get Info on the project in Xcode and change the Project Format to match the version of Xcode you're using (as of this writing, "Xcode 3.2-compatible").

You can delete the derived data as well, but unless you've updated your project format the bug will reoccur almost immediately. (It may happen even after updating your project format, but I used to have to delete DerivedData several times a day, and I think I've only done it once since fixing the project.)

As noted elsewhere, switching to LLVM may help. But as I update this answer (2012), you should be using LLVM anyway.

1
  • Restarting Xcode a few times and switching this preference back and forth a few times fixed it for me. I set my compiler to LLVM 2.1.
    – Sam Soffes
    Commented May 31, 2011 at 5:24
10

I found a way to avoid this bug. I have seen the bug appears every time I modificate a file which is imported in the prefix.pch.

Try to import your own file on the top of the imported list above UIKit.h and Fonudation.h and NOT at the end as everyone does.

In my prefix.pch file :

#ifdef __OBJC__
    #import "myFile.h"
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif
2
  • 1
    Fixed for me.. love you. What a headache
    – Morgz
    Commented Jun 26, 2012 at 11:12
  • 1
    Worked great :) thanks...EDIT: just kidding, changing the order didn't let me project compile. 2nd EDIT: need to be careful if myFile.h uses <UIKit/UIKit.h>...now working!
    – VTS12
    Commented Jul 10, 2012 at 19:27
5

There seems to be a myriad of proposed causes and solutions to this problem, and I think I've tried the majority of them. What finally worked for me (in Xcode 4.1) was to:

  • delete references to the problem files in the project navigator
  • move the problem files from the project folder in the Finder
  • back in the project navigator, right click and choose Add Files to...
  • find the files I had just moved and add them back into the project making sure that "Copy items into destination group's folder (if needed)" was selected.

Code Sense restored.

To be extra specific, my exact issue is when I create a new class via right click in the project navigator, about 30 - 40% of the time code sense does not work in the new class's header file. Interestingly, it does work in the implementation.

Things I've tried which failed:

  • deleting derived data folder in the Organizer
  • deleting derived data folder in the Finder
  • creating a whole new class from scratch (Why this didn't work I have no idea.)
  • changing the Syntax Coloring language
  • changing the compiler to and from all options multiple times
  • specifying a specific Headers Search Path

I'd love other possible suggestions to put an end to this issue cause it's really annoying!

1
  • This worked for me in XCode 9.3beta for .hpp files that were in subfolders of a folder reference. They were only referenced by clang module.modulemap files defining use of .hpp for each module. 9.1 and 9.3beta were broken, all above bulleted failed attempts also failed for me. Simply remove the folder reference and add it back. Error highlighting returned.
    – Asher
    Commented Feb 15, 2018 at 20:39
4

I had this problem as well. I had previously turned off indexing to speed up xcode operations and didn't realize at the time it would stop some of the code highlighting. If you have done this you can turn indexing back on by entering this in terminal:

defaults write com.apple.dt.XCode IDEIndexDisable 0

if you want to turn indexing off enter this into terminal:

defaults write com.apple.dt.XCode IDEIndexDisable 1
3

Had the same problems in Xcode 4.0.2. Code sense was working in every but two files, one .m file and its corresponding .h file. Tried everything - except rebuilding the code sense index, because I couldn't find the button anywhere - nothing worked. In the end I deleted the correlated files, the .m, .h and the .xib. Created new files, now everthing's working as expected.

2

In the addition to what tewha did I had to click "Rebuild Code Sense Index" button. It's at the bottom of "General" tab in Get Info on the project.

0
2

I had this problem on just one of my .m files, and after trying a lot of the things above it turned out XCode had at some point removed the .m extension. It was still listed in the project navigator as 'Myclass.m' but right clicking it and selecting Show in finder revealed the file was just called 'Myclass' (And was oddly placed in the en.lproj subfolder!).

Removing the reference from the project navigator, renaming and moving the file and re-adding it to the project fixed my problem.

2

If you notice that this is only happening on some of your files, make sure the .m file is a member of your target.

2
  • Great stuff. This is exactly what I needed. Commented Nov 14, 2012 at 21:33
  • Thank you! I've had syntax highlighting fail for a couple of reasons but this time that was it.
    – Form
    Commented Jun 15, 2013 at 4:22
1

Syntax coloring, auto completion, jumping to header files, etc is completely busted for me since XCode4. My symbol navigator view is completely empty. Hadn't realized how dependent I had become on the autocompletion, my productivity has dropped by a factor. What's strange is that my team-mates are seeing various combinations of missing functionality - only I am lucky enough to have lost everything. FWIW I am on the latest gen MBP.

1

I had the exact same problem but none of the above worked for me in the end I had to open xcode go to

File>Open Recent> Clear Menu

This Fixed the issue for me it seems that when i imported a github project that screwed up my code sense after clearing the Recents and then reopening the project everything worked fine.

1

Search for 'GCC_INCREASE_PRECOMPILED_HEADER_SHARING' in build settings and change it to YES. - This worked for me!

enter image description here

1

In my case, only one .m file has this problem. The autocomplete pops up fine, but it doesn't show everything. For example, when I type "NS" then autocomplete pops up only with "NSMutableDictionary" only and there isn't anything else! I tried everything, searched everywhere for 1 hour+ but nothing fixed it.

Then out of curiosity I deleted a comment block that I pasted earlier at the end of the .m file (below the @end word). After deleted that, autocomplete works again as normal!

Here's the culprit: enter image description here

So, if your autocomplete only fails on one file, might want to check that and delete everything below @end word.

0

What worked for me was changing the compiler to "LLVM Compiler 2.0".

0

Code sense was working for most files with the exception of 3 or 4 .m/.h files. I tried everything above, and the only thing that worked for me was drct's solution. I closed xCode, moved the project to a different folder and re-opened.

I find now, if I right click on a folder (or Group) in the Project Navigator and select 'New File..' Code Sense does not work.

If instead, I use the main menu and select 'File >> New >> New File' code sense works fine.

0

One thing I encountered today and which affected the code coloring is that I accidentally added a header (.h) file in Target -> Build Phases -> Compile Sources. Once removed, the code color magically came back :)

0

Sometimes addding multiline comments at the end of the @end statement in the code prevents auto completion in the Xcode 6.0.1. I had the same issue. Just check it out..

0

Why I am happy again :)

I had this problem, but somedays before I disabled XCode indexing process.

Resolved it by putting this command in terminal. I hope it helps somebody.

defaults write com.apple.dt.XCode IDEIndexDisable 0

And yes I am using Xcode 7.0

1
  • Felonious CodeMonk answer is also useful. Commented Oct 15, 2015 at 7:26
0

Try to close and open the XCODE IDE.

0

What helped me is moving the file that has the issue to another folder and return it back

0

I spent the better part of 3 days tracking this issue down so I figured I'd add my experience FWIW:

I had an Objective-C based project that originally had 2 targets: a main UI app and a command-line debugHelper tool. I wanted to make the debugHelper tool self-contained so I pulled only the classes into it that I needed from the main app's sources. This worked fine.

I later refactored much of the main app's core functionality into several stand-alone frameworks which were built to support modules. During this refactoring, the debugHelper's target lost its references to that directly pulled-in source code. To get it to work again, I repeated the process to link in and include only the necessary files directly, which ended up causing the following problem.

While working on the main app scheme and target, most of the 200-300 classes in the common framework had lost their syntax highlighting and refactoring ability, but only in the .h files. The solution ended up being to ditch the idea of directly pulling in individual files into debugHelper, and instead link against these core frameworks.

Not the answer you're looking for? Browse other questions tagged or ask your own question.