Xcode Swift Syntax Highlighting and Code Completion Completely Broken

I am having so many problems using Xcode 7.3 with a large swift and objective c project. The syntax highlighting and code completion with swift files is just plain awful.


The code in the editor is usually just black, code completion is non-existent, clicking on variables to see their type will return either a big "?" overlay, an <<ErrorType>>, or a No Help Available.


It is mostly files which interact with objective-c in a framework.


As an example, you can look at the new CareKit workspace:


https://github.com/carekit-apple/CareKit

There is a 'CarePlanStoreManager.swift' file where you will see the issues (among others).

This obviously impacts productivity in a MAJOR way. I do not understand how we can be expected to build large-scale apps this way. Having tools that work is essential! Swift continues to evolve and have new features added, but really having an editor that works is far more important.

And keep in mind, things work fine with simple projects - little sample apps. This is in a large application, where the app is almost all in swift, but our frameworks or pods are in objective-c.

I really don't understand how people aren't more up in arms over this. It makes me think that people tinker with swift more than anything, but their real work is still being done with Objective-C.

Anyway, sorry for the rant. I've just been at my wits end because I moving much more slowly than normal. I REALLY hope these problems are unique to my installation of Xcode or something, but I have tried literally everything.

If anyone has ideas, suggestions, etc., PLEASE post your thoughts.

Thanks,

Jason


Accepted Reply

I got help from an apple engineer at WWDC on this issue and resolved it.


The problem stemmed from cocoapods... Apparently cocoapods was copying .h files into the build directory and SourceKit was getting confused.


I'm not entirely sure why the .h files were being copied - they aren't needed there.


So the fix was to add a post-build script in your build phases section that removes the headers after a build.


It would look something like this:


function removeHeaders() {
    find $BUILD_ROOT/Debug-iphonesimulator/  -name '*.h' -exec rm -f {} \;
}
removeHeaders


Hope this works for others.

Replies

FWIW I'm not seeing the same problem with that CareKit project. (This was with Xcode 7.3.1, BTW.)


There are certainly times when Xcode is slow in catching up with its background compiling/indexing, which means that things like autocomplete or search don't fully work as expected. I don't know why it's worse on some occasions than on others.


I'd suggest you keep Activity Monitor running, sorting on descending CPU% usage. If you see anything there that's consuming more than about 0.5% for any length of time, you should make sure you understand why. For example, a few days ago, I found SourceKit (the part of Xcode that does basic syntax analysis and syntax coloring) using 200% continuously, and closing the project didn't help. Obviously something bad was going on. On other occasions, I've found an mds-related process (spotlight indexing) using an apparently modest amount of CPU and I/O, but still killing system responsiveness.


If you can recreate the problem, you can try capturing Xcode state with a "sysdiagnose Xcode" in a Terminal window, and submit the output as a bug report. You can also try things like quitting and relaunching Xcode, or even rebooting, but remember that if the problem is that something else is temporarily hogging resources, trying to do *more* things may not be immediately productive.

I got help from an apple engineer at WWDC on this issue and resolved it.


The problem stemmed from cocoapods... Apparently cocoapods was copying .h files into the build directory and SourceKit was getting confused.


I'm not entirely sure why the .h files were being copied - they aren't needed there.


So the fix was to add a post-build script in your build phases section that removes the headers after a build.


It would look something like this:


function removeHeaders() {
    find $BUILD_ROOT/Debug-iphonesimulator/  -name '*.h' -exec rm -f {} \;
}
removeHeaders


Hope this works for others.

Now, can use :


function removeHeaders() {
    find $BUILD_ROOT/Debug-iphoneos/  -name '*.h' -exec rm -f {} \;
}
removeHeaders

I created a Cocoapods bug report for that: https://github.com/CocoaPods/CocoaPods/issues/6424

I just removed the specific subdir reference from the script - doesn't seem to be any harm in that


function removeHeaders() {
    find $BUILD_ROOT/  -name '*.h' -exec rm -f {} \;
}
removeHeaders

Taking a nuclear approach to .h files will also remove any umbrella headers that you're supposed to have if you're using/building frameworks. Not necessarily approprate for all scenarios.

I use XCode10.1 with Swift 4.2 and hanve same problem.

The script is effective.

But but but it makes debugger doesn't work.

https://stackoverflow.com/questions/52728986/how-to-fix-xcode-10-0-debugger-it-is-not-fully-functioning

Building the project fixes the issue for me. Though this is a bit annoying at times.