Mastering Xcode 4 - Tips & Tricks

Code (Non)Sense

Tips & Tricks Apr 07, 2011 1 Comment

I’m seeing lots of reports of people having trouble with CodeSense and syntax highlighting not working properly in early versions of Xcode 4. While this is almost certainly a bug we’ll have to wait for Apple to fix, there’s a simple work-around that seems to work more often than not.

Xcode 4′s concept of a Derived Data subfolder for each project means that, among other things, the project index from which CodeSense and syntax highlighting get their information, is stored in an easy-to-nuke location. To nuke a project’s index, forcing Xcode to re-index a project and hopefully fix its issues, you use the Organizer window. Here’s how:

  1. For completeness (or OCD satisfaction), close the project but keep Xcode open.
  2. Open the Organizer window (Window > Organizer or Cmd-Shift-2).
  3. Select the Projects tab.
  4. Select the affected project from list on the left.
  5. Near the top of the right-hand pane, find the Derived Data section and click the Delete… button to its right.
  6. Confirm the deletion (this will only wipe out derived data – it won’t affect the contents of your project) and close the Organizer.
  7. Re-open your project and let Xcode re-index it. This may take awhile for large projects. Be patient.
  8. When Xcode is done re-indexing you might want to build the project (Cmd-B) to make sure syntax highlighting isn’t broken because a previously-unreported compile error.

That (and making sure your code actually compiles) should resolve some of the more common CodeSense and syntax highlighting problems.

Happy coding!

One Response to “Code (Non)Sense”

  1. Fix Your Xcode Project Index | Nick's Rant says:

    [...] and symbol lookup (including the quick-open feature, which I use a lot). Here’s a useful solution if you find yourself in this situation. Select your project in the Xcode Organizer and delete its [...]