6
votes

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.

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

3
it might also be worth to: clean project; clean DerivedData; remove and reinstall Xcoderadex
cleaning the project solved it for meFanckush

3 Answers

21
votes

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.

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

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

7
votes

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

Finally I found my Xcode logs SourceKitService crashed error,and found the answer on 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

defaults delete com.apple.dt.Xcode
1
votes

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