swift - Swift Playground 中没有这样的模块 'Cocoa'

标签 swift swift-playground

我正在尝试遵循 WWDC Playground session 中使用的一些代码,我正在尝试导入 Cocoa 框架:

import Cocoa

但是我在助理编辑器中得到以下错误

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

如果有帮助的话,我在视频的 41:20。

最佳答案

您使用的是 iOS playground(基于 UIKit),而不是 OS X playground(基于 Cocoa)。尝试创建一个新的 Playground 并选择“OS X”而不是“iOS”作为类型。之后它应该可以正常工作。

您还可以在 Playground 设置→平台下的文件检查器( View →检查器→显示文件检查器)中更改现有 playground 的类型。

默认情况下,新的 iOS playground 是使用样板创建的,包括 import UIKit; OS X Playground 是使用包括 import Cocoa 的样板创建的,因此如果您发现自己手动输入“import Cocoa”,这可能是您输入错误类型的线索。

关于swift - Swift Playground 中没有这样的模块 'Cocoa',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24099364/

相关文章:

ios - Swift 中的 Playgrounds 有什么用?

arrays - 如何保存整个整数数组?

ios - 如何覆盖目标平台中不可用但在 Base SDK 中可用的方法

ios - App store 拒绝了我的应用程序崩溃,但它从未通过大量测试为我崩溃

xcode - 使用 OS X 平台的 Swift Playground 中没有这样的模块 'Cocoa'

swift - 如何在 .playground 中写入文件?

ios - SceneKit 中声明的 func hitTest 导致 Playground 崩溃

ios - 来自 Firebase 数据库的 TableViewCell 数据

ios - 警告 : Unexpected version number in 'available' attribute for non-specific platform '*'

swift - 如何在swift中加载popover