SourceKitService Terminated

I believe I may have found a more general purpose solution. Below are the steps I used to encourage Xcode not to produce the SourceKitService Terminated error.


The symptoms I was having:

  • When I would start up a new playground, I would receive an error about not being able to communicate with the playground (Error running playground: Failed prepare for communication with playground. See this image on twitter.
  • When I would switch the playground from OS X to iOS, I would receive another error (unfortunately I did not write that one down).
  • When I would start to type in an iOS based Swift project, attempting to use code completion/intellisense on any UIKit specific class, I would receive the SourceKitService Terminated issue in this thread.

Debugging process:

  • I started by looking through google for SourceKitService, this got very little.
  • I then started monitoring Console.app while using Xcode. This showed a couple errors:
    • IDEPlaygroundDocument: Error encountered running playground
    • com.apple.CoreSimulator.CoreSimulatorService[3952]: The runtime for the selected device is not installed.

What I did to correct this issue.

If you are only having an issue within the context of a Swift project, try this alone first. If that doesn't work, then try all of the steps further below.

  1. Open your project and change the target's deployment target to something <= 7.1.

The more lengthy and involved process. (The first 3 steps are not for sure helpful, but I did them, and so record them here)

  1. Completely delete all copies of Xcode on your system.
  2. Restart your computer.
  3. Reinstall Xcode6-beta only.
  4. Verify that you still have the issue in playground and/or projects.
  5. Open iOS Simulator.
  6. Hardware -> Device -> Manage Devices
  7. Remove all devices.
  8. Recreate all devices you want. I appended the iOS version to the end of the name, just because.
  9. Restart Xcode and the simulator.
  10. Verify that at least playgrounds no longer throw issues when switched from OS X to iOS.
  11. Open your project and change the target's deployment target to something <= 7.1.

Analysis

It appears the issue is with Xcode6 not being able to properly find, and connect, to the simulator. I have not been able to determine why this is the case, but this has allowed me to continue developing with Swift. This may have to do with the fact the simulator binaries seem to have moved.


The answer to mine (Xcode6-Beta7) was simply to delete the Derived Data folder.

Preferences > Locations > Derived Data > click the arrow to open in Finder > trash it.

Hope this helps someone. There's obviously many reasons why this crash can occur.


SourceKitService crashes on my system as soon as I type

extension foo {

I'm using Xcode 6 beta 6 and it does not matter if I type it into an empty file or add it to an existing one. As soon as the source contains one extension block, it will crash. This happens even on newly created projects.

My "solution" is to avoid extension in the sources I'm currently working on. I comment out the end of a class block and the beginning of the extension block. As soon as I have finished my work on the class, I comment them in again:

class MyClass {

    [... my stuff ...]

//}
//
//extension MyClass {

}

You just need to delete the "ModuleCache", this is some kind of cache used by Xcode for Autocompletion.

Copy and paste the following line in the Terminal:

rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache