43

My project was created in Xcode 3, I'm opening it in Xcode 4 and notice the following:

  • 'Jump to Definition' no longer works with my own symbols (However UI* and even TT* symbols do work fine!)
  • Auto-complete / 'Code sense' is as bad as Xcode 3, i.e., it suggests everything
  • My projects' classes do not show up in the class navigator (Again, system and Three20 classes do show up!)

When creating a new Xcode 4 project however, these features do seem to work. Unfortunately the only workaround seems to be to recreate the project and re-import everything. This project is too large!

Things I've tried:

  • Removing the derived data in the organiser
  • Cleaning the project
  • Installing both Xcode 4 Gold Master and Final versions

Update

  • This bug has not been resolved in Xcode 4.0.1.
Moshe
  • 57,511
  • 78
  • 272
  • 425
Jimmy
  • 639
  • 1
  • 5
  • 9
  • I have this problem as well - have tried reindexing to no avail. Anyone able to suggest something else? – Maria Zverina Mar 15 '11 at 14:40
  • Same problem. Works fine for new/spall projects, but with my existing, large project it works badly. – Nick Moore Mar 18 '11 at 14:26
  • seems like small projects work just fine – hfossli Apr 01 '11 at 07:41
  • I have this problem as well, seems to still be a problem in 4.0.2 too. – makdad May 15 '11 at 23:36
  • Me too on 4.0.2 - works for 10-20 minutes at a time, then autocomplete can't even find the foundation classes anymore. Building, cleaning, restarting Xcode helps 50% of the time, the other half of the time it comes back after 10-20 minutes of me working without autocomplete. – RickiG Jul 31 '11 at 15:11
  • I just upgraded from 4.0.3 to the current version of Xcode (4.2 as of this writing), and my autocomplete problems went away. – clozach Oct 13 '11 at 22:34
  • FWIW, I made an alias to touch the auto included prefix header which always fixes things. I call it "pch_touch" and added it to my .bashrc / .profile. Kind of sad and ghetto, but hey, it gets the job done. alias pch_touch='touch /path/to/your/apps/Prefix.pch' Within about 1-2 sec of touching the pch file, syntax coloring comes back on, which is a sign code completion/jumping will be now working too. – Eric G Mar 12 '12 at 19:23
  • Duplicate of http://stackoverflow.com/questions/1627033/xcode-code-sense-color-completion-not-working/5958336#5958336 ? – Arkaaito Apr 08 '12 at 23:26

15 Answers15

67

On Window Menu:

  1. Organizer
  2. Projects tab
  3. Your Project
  4. Delete Derived Data
  5. Restart Xcode

A little tip from other's answer:

After step.4 don't rebuild the project but just restart Xcode.

xhan
  • 6,057
  • 4
  • 33
  • 47
  • 2
    See my comment above, but I always fix it by simply touching the .pch file in my project. I used to also delete Derived Data, but this seems faster. (I made an alias in my .bashrc to touch the .pch file. No restart required) – Eric G Mar 12 '12 at 19:24
  • This brings back autocomplete, but it also ruins the included project - RestKit in my case. – Hlung Mar 23 '12 at 09:12
  • I tried the above steps, but "Jump To Definition" is still greyed out for me. – jowie Aug 23 '13 at 11:51
16

What worked for me when i lost xcodes super nice code hinting was:

Window(menu) -> Organizer(menu) -> Projects(tab)

then

Press delete Derived Data (this is the same as going to the folder and deleting it manually)

BUT!!!!! at this step dont rebuild but shut down xcode and reopen of the project. This worked for me.

yeahdixon
  • 6,647
  • 1
  • 41
  • 43
7

I had the same problem in XCode 4 final version today, working with my old XCode 3 project. The problem is related to an index of symbols that XCode creates. It should create a new index for you automatically, but it seems to take a long time in XCode 4. One possible solution is to go to ~/Library/Developer/Xcode/DerivedData and delete the old index. Restart XCode, and you should see it indexing. For 'Jump to Definition', you can hold down command and mouse over a method or class name, and you should see blue underlines, like hyperlinks. Then you can click on it to jump to definition.

gstroup
  • 1,064
  • 8
  • 16
  • Doesn't work, mark down. The accepted solution should be to POUND APPLE WITH BUG REPORTS SO THEY CAN FIX THIS IN XCODE 4! – PostCodeism Dec 22 '11 at 17:27
  • This works for me, but only for a minute or two. Then it back to being broken again :( – Sunkas Jun 07 '12 at 16:09
7

EDIT: It seems that if you have any custom header search paths to support multiple targets with shared code XCode 4 indexing will break and then assistant and codesense along with it. I have raised this as #ID 9182099 with Apple. There is also an issue that if you have any conflicting settings between project global and target specific build settings the index will fail to complete correctly. Make sure that your build settings are consistent.

I have just had this problem in a very large, multi target commercial project. As an additional pain all of the xib files would not show the controller in assistant view and none of the subclass/superclass/siblings/categories assistant views would work either.

After much searching and experimentation with deleting the indexes etc I was forced to create a new empty project and re-import everything. I know you have said that your project is too big for this but I dont think there is any other option available. In the end it has taken me most of a day to migrate my project completely. I suppose you could hold on hopefully for a resolution in a future point release but I chose to bite the bullet now to benefit from the productivity increases from the new features.

To achieve this I created a new "empty" project and then manually recreated the targets I needed. I then deleted the source and .plist files for the new targets leaving me again with an empty project with the three targets I needed.

I then just selected "add files.." to the project one folder at a time linking against target as required. I stopped and built each target as it was imported to deal with any compiler errors that the latest clang gave me.

If you have a complex group hierarchy that is not mapped to a file system folder structure then you will either need to recreate the groups after import or go through the painful process of moving all your files into subfolders and re-pointing the references in XCode.

You will also need to carefully check any custom build settings in the targets as well as relink any libraries you include. Also make sure you remove any bulk imported .plist files from the target linking.

Sorry if this is not the answer you had hoped for.

Rick
  • 1,828
  • 17
  • 14
  • 1
    12 Hours after writing this and my XCode project has once again lost all the assistant views for everything other than counterpart. I thinking this must be a bug in XCode 4 now. – Rick Mar 24 '11 at 09:06
  • I'm having the same problem. You may be on to something. – Zac Bowling Mar 30 '11 at 22:25
  • While I've not tried re-importing into a new project I did have some luck with custom header paths - i.e. adding a path to the project root at one point seemed to force it to re-index. However, it has also now broken again! – Jimmy Apr 04 '11 at 10:44
  • Hi, Rick. I thought it might be a good idea to update the original text to make it a little more clear that it didn't work. It wouldn't be too fun to go through the process you described before reading the comment where you mentioned that it doesn't work. – wbyoung Apr 19 '11 at 20:18
  • @wbyoung The actual process to get a clean project going still holds. I hoped my edit at the top would show that there are possible gotchas even after taking the long route. – Rick Apr 20 '11 at 16:07
  • My small project worked after I remove all custom header paths, those paths are not necessary though. However I can't image what would happen if I have a large project and requires custom header paths. So do u or Apple has some better solutions on this now? – Zhao Xiang Feb 08 '12 at 05:20
  • Apple closed the ticket as fixed in the 4.2.1 release. However I have not had a chance to confirm it yet as I have moved onto another project and don't have access the to one that was causing me pain. – Rick Feb 22 '12 at 16:04
4

http://three20.info/article/2011-03-10-Xcode4-Support worked for me. Specifically erasing the Build directory of three20. Strangely it worked even when the said build was made in xcode4. CodeSense started working the moment I erased the three20 build dir, I didn't even have to recompile or reload the project.

GreatWiz
  • 735
  • 4
  • 8
  • Actually it seems that I need to keep erasing the said dir after every build. Making those test builds quite slow. – GreatWiz May 15 '11 at 19:33
  • Worked for me. My problem was because i moved my project from one computer to the other. – clenemt Aug 29 '11 at 14:05
2

This just worked for me:

  • Open your Xcode project.
  • Open up a command prompt in your project directory and type:

    touch MyProject.xcodeproj/project.pbxproj

  • Watch as syntax coloring and other stuff gets fixed before your eyes.

  • Reopen your project (or adjust a project setting) if your project schemes get reset to "My Mac" for iOS projects.
Christopher Rogers
  • 6,759
  • 1
  • 22
  • 13
2

I fixed the problem by removing derived data in th Organizer, running touch MyProject.xcodeproj/project.pbxproj and re-opening the project. After re-opening it, it started indexing and then it was working again.

k3a
  • 1,296
  • 1
  • 15
  • 32
1

In our case the culprit turned out to be old version of the three20 libs. To get the project working I had to:

  1. Remove all references to three20 from the project
  2. Follow the instructions at http://three20.info/article/2011-03-10-Xcode4-Support

As soon as the new library was installed, xcode4 automatically reindexed. Code completion, jump to definition and even Refactor all work now. The Joy(tm) of working with Xcode is back! :)

In more general terms, any library that puts it header files into BUILT_PRODUCT_DIR is likely to have similar issues.

Maria Zverina
  • 10,863
  • 3
  • 44
  • 61
  • Outstanding! It's such a coincidence that my project also uses the Three20 library! – Jimmy Apr 18 '11 at 10:08
  • 1
    three20 isn't the only problem, I'm not even using that and the indexing is disabled whenever I update from GIT. It's an Xcode 4 bug. Probably the biggest barrier in iOS development right now! – PostCodeism Dec 22 '11 at 17:26
1

In my XCode 4 setup, it is 100% reproducible that setting the User Header Search Path will break codesense, especially "Jump to Definition", after a restart. I have create a new project, added my helper library as a subproject. If I include the headers with the User Header Search Path (recursive), I can compile, but autocomplete/navigation is broken.

Deleting the header search path, closing the project, and reopening, fixes it again.

Duane Fields
  • 1,331
  • 12
  • 20
  • This appears to work for me, but only for autocomplete and not for "jump to definition". Just by toggling recursive on one of my header paths, attempting to build, then toggling back, building again. – gak Sep 16 '11 at 21:51
1

Added this as a comment in a few places as well, so maybe Google juice will help get programmers up and running again... but anyway, I found if you just use the touch command on the YourAppName-Prefix.pch file it will get syntax highlighting/coloring and code completion/jumping back on without having to delete all your derived data or restart Xcode. I made this an alias in my .bashrc file.

alias pch_touch='touch /path/to/your/apps/Prefix.pch'

. ~/.bashrc

Within about 1-2 sec of touching the pch file, syntax coloring comes back on, which is a sign code completion/jumping will be now working too. Kind of sad such an otherwise awesome powerful tool is humbled by some metadata / statefulness bugs, but there ya go. At least it gets you back up and running and stops wasting your time.

Eric G
  • 1,429
  • 18
  • 26
0

I had this exact same issue. I have a project with a bunch of ViewControllers that extend a class I'm calling BaseViewController. I added the following code to BaseViewController.h and syntax coloring and code autocomplete broke! Even with repeated deletions of derived data the problem was still there. I can't believe it!!

@implementation UIView (FindFirstResponder)
- (UIView *)findFirstResponder
{
    if (self.isFirstResponder) {
        return self;
    }

    for (UIView *subView in self.subviews) {
        UIView *firstResponder = [subView findFirstResponder];

        if (firstResponder != nil) {
            return firstResponder;
        }
    }

    return nil;
}
@end

Commenting out this code solved my issues! I have XCode Version 4.4.1 (4F1003)

benathon
  • 7,455
  • 2
  • 41
  • 70
0

From this comment here I was able to debug a similar problem with my project, it seemed to be a bad -w flag that the clang preprocessor wasn't recognizing properly. Basically, running

defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

in Terminal increases the verbosity of the indexer, and should help you track down issues. Run Console.app and search for IDEIndexingClang.

damian
  • 3,604
  • 1
  • 27
  • 46
0

I had the very same problem here. No definition links, code sense or syntax highlighting. Removing derived data didn't work and even creating a new project did not make any difference. While it may not be the same problem you have, cleaning up the build settings (so that there are no conflicts between project and targets) like Rick said solved it for me (though I still don't know which setting(s) was/were causing the problem).

Sacha
  • 170
  • 1
  • 8
0

With regard to "Jump to Definition", try clicking on the Scheme selection button (the one near the top right of the window that displays a list of builds, devices, and simulators) then click back in the code editor and try Command-click or "Jump to Definition" again.

I've recently found that whenever "Jump to Definition" stops working I can do this and it works again for awhile. It's not a fix but has been a useful workaround.

John Lemberger
  • 2,689
  • 26
  • 25
0

I don't know if it helps someone, but I got the code indexing of my C++ project broken when I switched to Xcode 4. I haven't switched to Lion so I still have the 4.02 version. When creating the project in Xcode I would use the external build option, this didn't add the HEADER_SEARCH_PATHS correctly to the project. I found that using:

   cmake -G Xcode . 

to generate the xcode project, sets this variable correctly and enables the indexing of the entire project.

Jim M.
  • 96
  • 3