Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 223
jpiglet Avatar asked Oct 29 '14 16:10

jpiglet


People also ask

How do I import to SwiftyJSON?

To use SwiftyJSON, you have to download the correct version from the Git repository. Simply, drag the "SwiftyJSON. swift" into your project and import into your class: import SwiftyJSON.


2 Answers

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.

like image 61
matthew.healy Avatar answered Oct 16 '22 20:10

matthew.healy


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
like image 25
Sandy Duan Avatar answered Oct 16 '22 20:10

Sandy Duan