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:
- For completeness (or OCD satisfaction), close the project but keep Xcode open.
- Open the Organizer window (Window > Organizer or Cmd-Shift-2).
- Select the Projects tab.
- Select the affected project from list on the left.
- Near the top of the right-hand pane, find the Derived Data section and click the Delete… button to its right.
- Confirm the deletion (this will only wipe out derived data – it won’t affect the contents of your project) and close the Organizer.
- Re-open your project and let Xcode re-index it. This may take awhile for large projects. Be patient.
- 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.