Swift Playground 中没有这样的模块“Cocoa" [英] No such module 'Cocoa' in Swift Playground

查看:26
本文介绍了Swift Playground 中没有这样的模块“Cocoa"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循 WWDC 游乐场会话中使用的一些代码,我正在尝试导入 Cocoa 框架:

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'

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

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

推荐答案

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

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.

您还可以在 Playground Settings→Platform 下的 File Inspector (View→Inspectors→Show File Inspector) 中更改现有 Playground 的类型.

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

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

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.

这篇关于Swift Playground 中没有这样的模块“Cocoa"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆