Charlie Egan Charlie Egan - 7 months ago 122
Swift Question

No such module 'Cocoa' in Swift Playground

I'm trying to follow some of the code used in the WWDC playgrounds session, I'm trying to import the Cocoa framework with:

import Cocoa


But I get the following error in the assistant editor

Playground execution failed: error: <REPL>:3:8: error: no such module 'Cocoa'


I'm at 41:20 in the video if that helps at all.

Answer

You are using an iOS playground (UIKit-based), not an OS X playground (Cocoa-based). Try creating a new playground and choosing "OS X" as the type instead of "iOS". It should work fine after that.

You can also change the type for an existing playground in the File Inspector (View→Utilities→Show File Inspector) under Playground Settings→Platform.

By default, new iOS playgrounds are created with boilerplate including import UIKit; OS X playgrounds are created with boilerplate including import Cocoa, so if you find yourself manually typing "import Cocoa", it's probably a clue you've got the wrong type.

Comments