我在Xcode中遇到了一个问题,错误“源套件服务终止”正在弹出,所有语法高亮显示和代码完成都在Swift中消失了。我该如何解决这个问题?
下面是一个示例图像:
我在Xcode中遇到了一个问题,错误“源套件服务终止”正在弹出,所有语法高亮显示和代码完成都在Swift中消失了。我该如何解决这个问题?
下面是一个示例图像:
当前回答
对我来说(xcode 6.1),原因是我忘记采用我的子类协议。
例如,这是错误的:
protocol SomeProtocol { ... }
class A :NSObject, SomeProtocol {
...
}
class B : A {
...
}
这是可以的:
protocol SomeProtocol { ... }
class A : NSObject, SomeProtocol {
...
}
class B : A, SomeProtocol {
...
}
其他回答
为了解决这个问题,你的Swift代码可能会有一些奇怪的问题。例如,因为您正在复制和粘贴,所以有多个iboutlet的定义。通常这只是一个无法处理的语法错误。
我相信我找到了一个更通用的解决方案。下面是我用来鼓励Xcode不要产生SourceKitService Terminated错误的步骤。
我的症状是:
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.
调试过程:
我开始通过谷歌寻找SourceKitService,这得到了很少。 然后我开始监视控制台。应用程序,同时使用Xcode。这显示了几个错误: IDEPlaygroundDocument:运行游乐场时遇到错误 com.apple.CoreSimulator。CoreSimulatorService[3952]: The runtime for The selected device is not installed。
我做了什么来纠正这个问题。
如果您只是在Swift项目上下文中遇到问题,请先单独尝试一下。如果这不起作用,那么尝试下面的所有步骤。
打开项目并将目标的部署目标更改为<= 7.1。
更漫长和复杂的过程。 (前3步不一定有帮助,但我做到了,所以把它们记录在这里)
Completely delete all copies of Xcode on your system. Restart your computer. Reinstall Xcode6-beta only. Verify that you still have the issue in playground and/or projects. Open iOS Simulator. Hardware -> Device -> Manage Devices Remove all devices. Recreate all devices you want. I appended the iOS version to the end of the name, just because. Restart Xcode and the simulator. Verify that at least playgrounds no longer throw issues when switched from OS X to iOS. Open your project and change the target's deployment target to something <= 7.1.
分析
看来问题是Xcode6不能正确地找到并连接到模拟器。我不知道为什么会出现这种情况,但这让我可以继续使用Swift进行开发。这可能与模拟器二进制文件似乎移动的事实有关。
只要我输入,SourceKitService就会在我的系统上崩溃
extension foo {
我使用的是Xcode 6 beta 6,不管我是把它输入到一个空文件中,还是把它添加到一个现有的文件中。只要源代码包含一个扩展块,它就会崩溃。即使在新创建的项目中也会发生这种情况。
我的“解决方案”是避免在我目前正在开发的源代码中进行扩展。我注释掉了类块的结尾和扩展块的开头。我一完成这门课的工作,就会再次对它们进行评论:
class MyClass {
[... my stuff ...]
//}
//
//extension MyClass {
}
只是在这里添加一个潜在的解决方案,我不小心命名了一个类var与它的类型相同的名称:
class var Settings:Settings {
get { return classVarWorkAround.settings }
}
这肯定会使SourceKit崩溃。愚蠢的语法错误,但以防其他人犯同样的错误。
编辑:根据@Portland Runner:
类似地,如果将返回类型设置为func名称,则会得到错误。
func foo() ->foo{}
我在嵌套的objective - c++项目中也犯了同样的错误,该项目现在包含了带有Swift代码的框架。为了解决这个问题,我必须明确地构建框架。一旦我做了,那期就没了,再也不会回来了;)