Xcode code sense color/completion not working
Asked Answered
I

24

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.

Immobile answered 26/10, 2009 at 20:5 Comment(4)
I had the similar issue for one project only. Code sense color/completion just work fine for other projects. Did you solved it?Severin
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 completeImmobile
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 ?Horologium
As of Xcode 4.4, this problem seems to be a lot better.Angus
C
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.

Creature answered 8/12, 2009 at 20:59 Comment(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.Intention
B
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://mcmap.net/q/259079/-xcode-code-loses-syntax-coloring - but I don't see it in any of the answers there. Very curious.)

Beeeater answered 11/5, 2011 at 1:42 Comment(5)
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!Impartible
Worked for me in XCode 4 alsoKwei
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.Active
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.Hyperbaton
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...Boondocks
H
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 :)

Hydrargyrum answered 24/4, 2012 at 9:50 Comment(2)
This is better than the other answers here. And it works without restarting XCode.Emylee
Same here, I just used after about half an hour of searching, and it works! Doesn't even take much work...Largent
B
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
Backcourt answered 6/10, 2011 at 12:52 Comment(2)
Worked for me, Xcode 4.3.2. I was screaming because it worked half the time. THANKS!!!Sandblast
First 2 steps worked for me! Thnx! xcode 4.3.2. Upgraded to support new iPad but lost autocomplete on the way.Afflux
U
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.

Undirected answered 23/2, 2011 at 5:22 Comment(3)
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.Elope
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 ?Horologium
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.Boomkin
C
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.

Creature answered 8/12, 2009 at 20:59 Comment(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.Intention
H
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
Horologium answered 24/5, 2012 at 8:13 Comment(2)
Fixed for me.. love you. What a headacheSharpeyed
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!Farfetched
T
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!

Trackman answered 2/10, 2011 at 5:50 Comment(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.Collaborative
A
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
Accounting answered 30/8, 2013 at 18:46 Comment(0)
G
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.

Goggleeyed answered 26/4, 2011 at 21:26 Comment(0)
O
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.

Obsolete answered 28/8, 2010 at 10:3 Comment(0)
C
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.

Counterfactual answered 8/3, 2012 at 8:54 Comment(0)
M
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.

Measureless answered 5/9, 2012 at 16:4 Comment(2)
Great stuff. This is exactly what I needed.Rationalize
Thank you! I've had syntax highlighting fail for a couple of reasons but this time that was it.Whomp
T
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.

Terri answered 24/3, 2011 at 21:5 Comment(0)
L
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.

Labannah answered 30/1, 2012 at 11:37 Comment(0)
P
1

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

enter image description here

Praedial answered 5/9, 2013 at 11:7 Comment(0)
H
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.

Hedveh answered 11/2, 2016 at 11:54 Comment(0)
S
0

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

Susysuter answered 6/7, 2011 at 7:51 Comment(0)
A
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.

Annulet answered 15/9, 2011 at 10:11 Comment(0)
E
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 :)

Exhibitioner answered 11/1, 2012 at 12:34 Comment(0)
D
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..

Diviner answered 3/1, 2015 at 9:0 Comment(0)
C
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

Casebook answered 15/10, 2015 at 7:18 Comment(1)
Felonious CodeMonk answer is also useful.Casebook
T
0

Try to close and open the XCODE IDE.

Twinkle answered 13/3, 2016 at 11:33 Comment(0)
Y
0

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

Yeta answered 19/1, 2023 at 7:31 Comment(0)
Q
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.

Quintessa answered 11/9, 2023 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.