03 June 2011 by Published in: Code, iphone 13 comments

Here’s how to fix it:

  1. Close the project, leaving XCode still running.
  2. Open XCode’s Organizer window, go to the Projects Tab, select the correct project, and hit the Delete button next to “Derived Data”.
  3. Quit XCode.
  4. Navigate to your project’s .xcodeproject file in Finder.  Right-click, choose “Show Package Contents.”
  5. Leave the project.pbxproj file, but delete the project.xcworkspace file, any .pbxuser files, and the entire userdata folder.
  6. 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”
  7. 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.

Like this post? Contribute to the coffee fund so I can write more like it.

Comments

  1. Mon 18th Jul 2011 at 12:09 pm

    Saved me some headache time! Thanks!

  2. Joe K.
    Mon 26th Sep 2011 at 2:01 pm

    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!

  3. Sat 19th Nov 2011 at 9:41 am

    Thank you very much! Deleting the project’s user data did it.

  4. Kevin
    Mon 05th Dec 2011 at 10:51 am

    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…

  5. Tue 06th Dec 2011 at 12:02 pm

    Thank you so much. Helped out in a tight spot.

  6. Wed 25th Jan 2012 at 7:14 am

    For me it didn’t work :(

  7. Chad Seldomridge
    Wed 22nd Feb 2012 at 7:05 pm

    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.

  8. Bob
    Mon 02nd Apr 2012 at 4:33 pm

    Thanks. That did the trick. Good thing too. Xcode is practically unusable without AutoComplete.

    -Bob

  9. nikolaus hege
    Sat 23rd Jun 2012 at 10:24 am

    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.

  10. Steve Riggins
    Wed 22nd Aug 2012 at 7:55 pm

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

  11. AHHP
    Sun 13th Jan 2013 at 9:37 am

    Thanks a lot.

  12. Thu 25th Apr 2013 at 1:49 am

    WOW just what I was searching for. Came here by searching for code

Add comment

Copyright © 2011 Drew Crawford, All Rights Reserved
Powered by WordPress

Page optimized by WP Minify WordPress Plugin