Xcode code sense color/completion not working

XcodeSyntax Highlighting

Xcode Problem Overview


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.

Xcode Solutions


Solution 1 - Xcode

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][1], which indicates that it got it in turn from [https://stackoverflow.com/questions/2138047/xcode-code-loses-syntax-coloring][2] - but I don't see it in any of the answers there. Very curious.)

[1]: http://blog.slidetorock.com/xcode-4-code-sense-autocompletion-problems "this blog post" [2]: https://stackoverflow.com/questions/2138047/xcode-code-loses-syntax-coloring "this SO question"

Solution 2 - Xcode

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 :)

Solution 3 - Xcode

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

Solution 4 - Xcode

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.

Solution 5 - Xcode

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.

Solution 6 - Xcode

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

Solution 7 - Xcode

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!

Solution 8 - Xcode

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

Solution 9 - Xcode

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.

Solution 10 - Xcode

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.

Solution 11 - Xcode

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

Solution 12 - Xcode

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.

Solution 13 - Xcode

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.

Solution 14 - Xcode

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.

Solution 15 - Xcode

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

enter image description here

Solution 16 - Xcode

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

Solution 17 - Xcode

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.

Solution 18 - Xcode

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 :)

Solution 19 - Xcode

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..

Solution 20 - Xcode

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

Solution 21 - Xcode

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.

Solution 22 - Xcode

Try to close and open the XCODE IDE.

Solution 23 - Xcode

For someone still don't know why. Open with XCode 8.2 work for me. Seem newest XCode got this issue

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmgaView Question on Stackoverflow
Solution 1 - XcodeArkaaitoView Answer on Stackoverflow
Solution 2 - XcodeSergey KopanevView Answer on Stackoverflow
Solution 3 - XcodekarlogeoView Answer on Stackoverflow
Solution 4 - XcodeThomas MüllerView Answer on Stackoverflow
Solution 5 - XcodeSteven FisherView Answer on Stackoverflow
Solution 6 - XcodebookerView Answer on Stackoverflow
Solution 7 - XcodeGnarlyDogView Answer on Stackoverflow
Solution 8 - XcodeFelonious CodeMonkView Answer on Stackoverflow
Solution 9 - XcodedrctView Answer on Stackoverflow
Solution 10 - XcodekolinkoView Answer on Stackoverflow
Solution 11 - XcodeAndyView Answer on Stackoverflow
Solution 12 - XcodeSunil GowdaView Answer on Stackoverflow
Solution 13 - XcodeAnthony McCormickView Answer on Stackoverflow
Solution 14 - XcodeMarkusEkbladView Answer on Stackoverflow
Solution 15 - XcodethatzpremView Answer on Stackoverflow
Solution 16 - XcodeChris LivdahlView Answer on Stackoverflow
Solution 17 - XcodeNiallView Answer on Stackoverflow
Solution 18 - XcodeMarko HlebarView Answer on Stackoverflow
Solution 19 - XcodeDhaval H. NenaView Answer on Stackoverflow
Solution 20 - XcodeGajendra K ChauhanView Answer on Stackoverflow
Solution 21 - XcodeGeneCodeView Answer on Stackoverflow
Solution 22 - XcodeidanudaView Answer on Stackoverflow
Solution 23 - XcodeHieu TranView Answer on Stackoverflow