我在Xcode中遇到了一个问题,错误“源套件服务终止”正在弹出,所有语法高亮显示和代码完成都在Swift中消失了。我该如何解决这个问题?

下面是一个示例图像:


当前回答

今天有同样的问题,事情是与println,我只是尝试了旧的NSLog风格打印一个值:

// something like this
println("value = %@", valueObj)

我们应该如何在swift中组成字符串的方式已经从printf风格演变为内联风格,所以现在你可以像这样将你的值嵌入到格式字符串中:

"Here goes \(YOUR_VARIABLE)"

所以,对于上面的例子,解决方案是:

println("value =\(valueObj)")

其他回答

我相信我找到了一个更通用的解决方案。下面是我用来鼓励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-Beta7)是简单地删除派生数据文件夹。

首选项>位置>衍生数据>单击箭头打开Finder >垃圾。

很明显,这种崩溃的发生有很多原因。

你只需要删除“ModuleCache”,这是Xcode用于自动补全的某种缓存。

在终端中复制并粘贴以下代码行:

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

在xcode中,转到你的菜单栏>>窗口>> devices (shift+cmd+2),一个新的窗口将弹出,并在左下角,添加一个新的模拟器,特别是一个运行在iOS 8.0上的现有列表 编辑:你可能需要重新启动xcode

具有:http://www.reddit.com/r/swift/comments/2bznfo/error_running_playground_unable_to_find_suitable/

我想我找到了一个(可能还有很多)这种情况发生的原因。

在我的例子中,我通过桥接头导入Objective-C文件,桥接头具有以下true之一:

用于Objective-C导入的实现文件(.m)没有 App目标设置正确。 Objective-C文件只有头文件(.h),而没有 实现(.m)文件。(再一次,我认为这是“不”的一部分 适当的应用目标”设置,因为你只能在。m文件中设置目标 而不是。h文件)

修复Objective-C文件上的应用目标或在桥接头中删除这些文件的导入似乎都可以解决这个问题。

仅供参考-如果你需要设置头(.h)文件的目标,而该文件没有实现(.m)文件,你可以遵循以下简单的步骤