Here’s how to fix it:
- Close the project, leaving XCode still running.
- Open XCode’s Organizer window, go to the Projects Tab, select the correct project, and hit the Delete button next to “Derived Data”.
- Quit XCode.
- Navigate to your project’s .xcodeproject file in Finder. Right-click, choose “Show Package Contents.”
- Leave the project.pbxproj file, but delete the project.xcworkspace file, any .pbxuser files, and the entire userdata folder.
- Open the project in XCode. You will see XCode riding high on the CPU usage for around 10-60 seconds, depending on the size of your project. The activity window will say “Indexing”
- When your CPU spike returns to earth, code completion will be working again.
Unlike rebuilding the indexes alone, this procedure works every time. It’s unfortunate that XCode’s indexes are brittle enough to break once a week, but now you know how to fix it!
Is code completion working for system libraries and your own code, but not for one particular third-party library?
Make sure that if you’re using
#include "something.h"
syntax, the path to the .h files is in “User Header Search Paths” (not Header Search Paths).
Make sure that if you’re using
#include <something.h>
, the path to the .h files is in “Header Search Paths” (not User Header Search Paths).
When you build your project, the compiler appears to give you grace if you’ve accidentally put the header files into the wrong type of search path, but code completion is less forgiving.
Want me to build your app / consult for your company / speak at your event? Good news! I'm an
iOS developer for hire.
Like this post? Contribute to the coffee fund so I can write more like it.
Saved me some headache time! Thanks!
Thank you! Xcode 4 is so much better than any of its predecessors when it comes to code completion, except when it breaks at which point it’s very frustrating!
Thank you very much! Deleting the project’s user data did it.
Nice to see a new fix that I hadn’t tried but sadly, this still didn’t work. All of my .mm files are completely broken while all of my .cpp files are just fine. I’ve juggled the Syntax Coloring under Editor on the menu bar from Objective-C++, to Objective-C, to Default for file type and back again without any change also. I’ve checked all of my import statements and can’t find a problem. Total bummer…
Thank you so much. Helped out in a tight spot.
For me it didn’t work
I find that it’s my spotlight index that is the root cause. To fix it, I run mdutil from the Terminal: “sudo mdutil -Ea”
This rebuilds the indexes for all volumes, and makes Xcode work properly again.
Thanks. That did the trick. Good thing too. Xcode is practically unusable without AutoComplete.
-Bob
thanks this seems to have fixed a CPU issue I was having where Xcode was constantly using 30% CPU even when hidden and in the background.
As for code completion: Do yourself a favor and code with AppCode. Not only is the code completion leaps and bounds better, it also has proper refactoring tools, automatic property generation etc etc. Saves huge amounts of time every day.
Sadly this did not fix my issue. After rebuilding spotlight, and doing all of these tricks, I cannot #import ” any of my own files in my project. Nothing autocompletes. Fun
Thanks a lot.
WOW just what I was searching for. Came here by searching for code