Xcode7 code completion broken

In Xcode7, one of my project's targets' code completion and syntax highlighting are broken, at least for some of the files in the project. A different target, with almost the case exact code base, works fine! When I switch schemes the same files work just ok. They both share the same pch file. I've been juggling between Xcode6 and Xcode7, so not sure if that caused this, but I've cleaned out the DerivedData directory and restarted Xcode multiple times, but it still doesn't work. Both targets work just fine in Xcode6.


Any ideas on how to fix this?

Replies

How broken is syntax highlighting? If all the text is black, then SourceKit has crashed. If the keywords are colored, but nothing user-defined is colored, then the file isn't being indexed.


Xcode 7 still seems to fail to display some errors (either live in the editing pane, or in the errors navigator, or both). Try building your project and see if that produces errors you haven't seen yet. Fixing the errors (and rebuiliding again afterwards) should allow you to get back on track.

"nothing user-defined is colored, then the file isn't being indexed" ... this would be the problem. How do I get the file to be indexed? It's definitely not a build issue ... the target builds and runs fine. Just some files that refuse to be indexed.

If it works in a different scheme, then the most likely cause is that the target membership of the file is incorrect, or perhaps there's something wrong in the scheme itself.


Is this Swift or Obj-C?

Objective-C. The target membership seems fine ... how do I check whether there's something wrong with the scheme or not? It indexes most of the files just fine ... just a few (important ones) that are off

The scheme's build action specifies which targets to build. Check that the right ones are being built.


Assuming that's fine, then I'd start playing around with the file contents. What happens if you deliberately introduce an error? When you remove that error? What happens if you comment out all the methods? Put them back one by one?


Does the project have "Enable Modules (C and Objective C)" turned on? If it's off, try turning it on. If it's on, try turning it off, building, and turning it back on again.

When I set "Enable Modules (C and Objective C)" to No, the source files show all the highlighting and code completion. But it doesn't build becuase I am importing various modules into the app. When I turn it back to Yes and build, it builds fine but the problem returns. So something in modules is throwing it off but not sure what.

It may or may not be related, but I found this thread while facing a similar problem. Xcode stopped correctly auto-completing code in one Obj-c class fille. Even a simple instance variable added in the .h was unknown in the .m. Some framework where known other not.


After reviewing my recent changes, it turned out that the cause was a comment at the end of the .m file. This comment was /* */ format and added after the @end of the implementation. For some reason, moving this comment above the @end keyword solved the problem.

This should be top comment, if there was such a thing. Still relevant in 2017!