Xcode 6.1:在所有 OSX Swift 项目中突然没有这样的模块“cocoa”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26635952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:02:15  来源:igfitidea点击:

Xcode 6.1: no such module 'cocoa' suddenly in all OSX Swift projects

xcodemacoscocoaswift

提问by jpiglet

I have been using Xcode 6.1 without issue for several days but suddenly I'm getting the error no such module 'Cocoa'in all of my Swift files. This is an OSX project, not iOS and the problem happens on all projects, including newly created ones.

我已经使用 Xcode 6.1 好几天了,但突然间我收到错误消息,所有 Swift 文件中都没有这样的模块“Cocoa”。这是一个 OSX 项目,而不是 iOS,问题发生在所有项目上,包括新创建的项目。

I've verified and repaired disk permissions, checked the disk for errors, and reset Xcode to default settings.

我已经验证并修复了磁盘权限,检查了磁盘是否有错误,并将 Xcode 重置为默认设置。

采纳答案by jpiglet

Deleting and reinstalling Xcode solved the issue. Thank you radex for the suggestion.

删除并重新安装 Xcode 解决了该问题。感谢 radex 的建议。

回答by matthew.healy

I had this problem today in a Swift test-case class. I tried both of the suggested answers, but it didn't fix the issue. It turned out to be user-error - I had accidentally created an OS X test-case class in an iOS application.

我今天在 Swift 测试用例类中遇到了这个问题。我尝试了两个建议的答案,但没有解决问题。结果是用户错误 - 我不小心在 iOS 应用程序中创建了一个 OS X 测试用例类。

Which is to say that instead of import Cocoaat the top of my test-case file, I should have had import UIKit.

也就是说,不是import Cocoa在我的测试用例文件的顶部,我应该有import UIKit.

Figured it was worth leaving this as an answer to save people uninstalling and reinstalling Xcode without necessarily needing to.

认为值得将此作为答案,以节省人们卸载和重新安装 Xcode 而不一定需要。

回答by Sandy Duan

I encountered the same problem and reinstalled the Xcode,the problem still there.

我遇到了同样的问题并重新安装了Xcode,问题仍然存在。

Finally I found my Xcode logs SourceKitService crashed error,and found the answer on twitter

最后我发现我的 Xcode 日志 SourceKitService crashed 错误,并在 twitter 上找到了答案

open terminal and execute:

打开终端并执行:

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

It's works for me!

它对我有用!

or you can reset Xcode defaults by command line

或者您可以通过命令行重置 Xcode 默认值

defaults delete com.apple.dt.Xcode