No Such Module 'Cocoa' in Swift Playground

No such module 'Cocoa' in Swift Playground

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→Inspectors→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.

Xcode 6 Beta: No such module 'Cocoa'

You can't import Cocoa from an iOS playground or application. Make sure your code is running in a Cocoa playground (select OS X > Source in the new file dialog).

Playground Import: No Such Module 'Foo'

The solution, from Apple Support, was to adjust my Xcode Preferences. On Locations :: Advanced my configuration was 'Legacy'. By changing to 'Unique', and undoing any paths I'd attempted to insert, Playgrounds can now import frameworks.

no such module when Importing pods in swift playground

Not a direct answer to the issues you get from this tutorial, but there's a new tool to automatically generate Playgrounds with pods that I often use.

It's called ThisCouldBeUsButYouPlaying and the source is on GitHub.

Basically it extends the CocoaPods installer, which is then able to generate Playgrounds.

Install:

$ gem install cocoapods-playgrounds

Create a Playground with Alamofire:

$ pod playgrounds Alamofire

Create a Playground with multiple pods:

$ pod playgrounds RxSwift,RxCocoa

The new Playground will automatically open.

You will have to first build the project, to enable the pods, then the Playground will be available.

Sample Image

import Cocoa in playground Xcode giving me an error

You should only import Cocoa if you're working on code for OS X. UIKit is only for iOS so it sounds like you created an iOS playground. If you want to use Cocoa to follow a tutorial create a new playground and select OS X from the menu.

Getting 'no such module' error when importing a Swift Package Manager dependency

It turned out that Swift Package Manager implicitly depends on the project's Configuration names. I had them at live/qa instead of Release/Debug, and changing them back resolved the issue. Very odd, but I hope it saves you some trouble dear reader.

Error importing framework in Playground

I solved my problem with a different solution than Michael Welch's. I had my Xcode derived data setting different than original. Go to Preferences > Locations > Derived Data > Advanced and select Unique. This solved the framework not appearing in playground problem for me.

Derived Data

Swift Playground doesn't recognize Cocoa Touch initializer

NSDataBase64DecodingOptions is a RawOptionSetType which inherits from
NilLiteralConvertible, therefore you can specify nil for "no options":

let data = NSData(base64EncodedString: "SGVsbG8gd29ybGQNCg==", options: nil)

Update: As of Swift 2, NS_OPTIONS types get imported as conforming to the OptionSetType protocol, which presents a set-like interface for options. "No options" can be specified as the empty set:

let data = NSData(base64EncodedString: "SGVsbG8gd29ybGQNCg==", options: [])


Related Topics



Leave a reply



Submit