斯威夫特游乐场里没有这样的“可可”模块

时间:2022-03-31 11:14:56

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

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

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.

视频中我的成绩是41比20,如果有帮助的话。

2 个解决方案

#1


79  

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.

你使用的是iOS游乐场(基于uikit),而不是OS X游乐场(基于茧)。尝试创建一个新的游乐场,选择“OS X”而不是“iOS”。之后应该没问题。

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.

默认情况下,使用样板创建新的iOS平台,包括导入UIKit;OS X游乐场是用包括import Cocoa在内的样板文件创建的,所以如果你手工输入“import Cocoa”,这可能是你输入错误类型的线索。

#2


13  

If you are getting this or a similar type of error despite having the playground set properly, try the following:

如果你在适当地设置了运动场地后,却得到了这样或类似的错误,请尝试以下方法:

Close XCode and from the terminal run:

关闭XCode并从终端运行:

 rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"

Then reopen XCode and most times this fixes many Playground issues. I run this command quite frequently during an intensive Playground work session (sometimes as many as a few times per hour) and have found liberal use of removing the ModuleCache to solve a multitude of strange playground behaviors.

然后重新打开XCode,大多数时候,这修复了许多游乐场问题。我经常在高强度的操场工作期间(有时每小时几次)运行这个命令,并发现可以*地使用取消模块来解决大量奇怪的操场行为。

If you're still having issues with playgrounds you can try:

如果你仍然对操场有意见,你可以试试:

rm -rf ~/Library/Developer/Xcode/DerivedData

and/or

和/或

rm -rf ~/Library/Caches/com.apple.dt.Xcode

#1


79  

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.

你使用的是iOS游乐场(基于uikit),而不是OS X游乐场(基于茧)。尝试创建一个新的游乐场,选择“OS X”而不是“iOS”。之后应该没问题。

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.

默认情况下,使用样板创建新的iOS平台,包括导入UIKit;OS X游乐场是用包括import Cocoa在内的样板文件创建的,所以如果你手工输入“import Cocoa”,这可能是你输入错误类型的线索。

#2


13  

If you are getting this or a similar type of error despite having the playground set properly, try the following:

如果你在适当地设置了运动场地后,却得到了这样或类似的错误,请尝试以下方法:

Close XCode and from the terminal run:

关闭XCode并从终端运行:

 rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"

Then reopen XCode and most times this fixes many Playground issues. I run this command quite frequently during an intensive Playground work session (sometimes as many as a few times per hour) and have found liberal use of removing the ModuleCache to solve a multitude of strange playground behaviors.

然后重新打开XCode,大多数时候,这修复了许多游乐场问题。我经常在高强度的操场工作期间(有时每小时几次)运行这个命令,并发现可以*地使用取消模块来解决大量奇怪的操场行为。

If you're still having issues with playgrounds you can try:

如果你仍然对操场有意见,你可以试试:

rm -rf ~/Library/Developer/Xcode/DerivedData

and/or

和/或

rm -rf ~/Library/Caches/com.apple.dt.Xcode