我在Xcode中遇到了一个问题,错误“源套件服务终止”正在弹出,所有语法高亮显示和代码完成都在Swift中消失了。我该如何解决这个问题?
下面是一个示例图像:
我在Xcode中遇到了一个问题,错误“源套件服务终止”正在弹出,所有语法高亮显示和代码完成都在Swift中消失了。我该如何解决这个问题?
下面是一个示例图像:
当前回答
我在苹果的开发者论坛上找到了一个解决方案(需要登录,所以我也会在这里解释)。
TLDR:不要在Objective-C中导入与@interface同名的@protocol到Swift桥接头。例如,Facebook SDK有一个名为“FBGraphObject”的协议和接口。
以下是论坛帖子:
Adding Facebook SDK causes SourceKitService to crash. If you want to use beta 3 and you need Facebook SDK, one work around that I found and is working for me is refactoring Facebook SDK's @protocol FBGraphObject and renaming it to something like @protocol FBGraphObjectProtocol as an @interface FBGraphObject also exists and apparently SourceKit doesn't like it. It sure is a temporary solution just to keep you functional and you'll have to use Cocoapods or otherwise build Facebook SDK yourself rather than using the framework library. For the time being, you'll need to make sure you don't have conflicting @protocol and @interface declarations and that includes 3rd party libraries you may be using. This cost me today, hope it helps! Posted by e.parto on July 10, 2014
其他回答
我相信我找到了一个更通用的解决方案。下面是我用来鼓励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进行开发。这可能与模拟器二进制文件似乎移动的事实有关。
我在Xcode6 beta 3中创建了一个在beta 2中创建的项目,遇到了同样的问题。
这是因为swift语言中出现了新的突破性变化,即数组声明语法。
检查受影响的代码由于破坏性的变化在beta 3。
http://adcdownload.apple.com//Developer_Tools/xcode_6_beta_3_lpw27r/xcode_6_beta_3_release_notes__.pdf
我的例子之一是:
我不得不改变:
var tabBarController : UITabBarController = self.window?.rootViewController as UITabBarController;
to
var tabBarController : UITabBarController = self.window!.rootViewController as UITabBarController
结论:看起来如果源代码中有错误,在某些情况下这个错误是由Xcode产生的。
解决方案,直到bug被修复:手动检查错误:)
古德勒克!
只是在这里添加一个潜在的解决方案,我不小心命名了一个类var与它的类型相同的名称:
class var Settings:Settings {
get { return classVarWorkAround.settings }
}
这肯定会使SourceKit崩溃。愚蠢的语法错误,但以防其他人犯同样的错误。
编辑:根据@Portland Runner:
类似地,如果将返回类型设置为func名称,则会得到错误。
func foo() ->foo{}
在过去的几个月里,我几乎每天都有这种感觉。尝试了上面所有的方法,它只能暂时修复它。
最后,在两周前,我将DerivedData位置更改为一个新位置,而且我一次都没有遇到过这个问题。
我注意到,当我删除我的派生数据文件夹时,它会重新生成,由于某种原因大约是3GB。当我创建一个新文件夹时,它并没有重新生成所有这些数据。
希望这能帮助到一些人。
我的解决方案是更换模拟器。我使用的是iPhone 5S,当我切换到iPhone 5时,一切都很完美。希望未来的版本能完全修复它。