ios Xcode:有什么方法可以刷新/重新运行操场?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26112993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:55:08  来源:igfitidea点击:

Xcode: Any way to refresh/re-run the playground?

iosswiftrefreshxcode6swift-playground

提问by shim

The Playground in Xcode automatically updates as you type, but I can't figure out how to get the Playground to "re-compile".

Xcode 中的 Playground 会在您键入时自动更新,但我不知道如何让 Playground 进行“重新编译”。

In many cases this wouldn't matter, but if you're writing code that generates or uses random values it can be useful to run it a few times to make sure it's working. Is there any way to get the playground to reset / refresh / re-run?

在许多情况下,这无关紧要,但如果您正在编写生成或使用随机值的代码,运行几次以确保其正常工作会很有用。有没有办法让游乐场重置/刷新/重新运行?

Seen a few questions asking how to stop the Playground from auto-updating, but nothing for the opposite.

看到了一些询问如何阻止 Playground 自动更新的问题,但没有相反的问题。

Easiest way to do this seems to be to just edit the code (add and remove a space), or put in some kind of a loop... Just wondering if there's a menu shortcut etc.

最简单的方法似乎是编辑代码(添加和删除一个空格),或者放入某种循环......只是想知道是否有菜单快捷方式等。

回答by rintaro

Try Editor> Execute Playgroundfrom Xcode menu

尝试Editor>Execute Playground从 Xcode 菜单

enter image description here

在此处输入图片说明

I don't know what Reset Playgroundis, by the way.

Reset Playground顺便说一下,我不知道是什么。

回答by Cem Bego

Also, you can create your shortcuts.

此外,您可以创建快捷方式。

Xcode > Preferences > Key Binding > (Search Execute Playground)

Xcode > Preferences > Key Binding > (Search Execute Playground)

It is empty as a default, but you can assign anything.

默认为空,但您可以分配任何内容。

Xcode 11> Preferences > Key Binding > (Run Playground)

Xcode 11> Preferences > Key Binding > (Run Playground)

回答by shim

In addition to the other responses, playground execution can also be controlled with the button on the bottom bar above the debugger console. There are two buttons on the left side of the console; the one on the left opens/closes the console and the one on the right controls the execution of the playground and changes depending on whether the playground is currently running.

除了其他响应之外,还可以使用调试器控制台上方底部栏上的按钮来控制操场执行。控制台左侧有两个按钮;左边的一个打开/关闭控制台,右边的一个控制操场的执行,并根据操场当前是否正在运行而改变。

If you hover over the button a small black triangle will appear in the bottom corner of the button. If you long presson the button the menu in the screenshot below will appear, where you can change the execution mode of the playground between automatically or manually running. If it's automatic, then it should run once every time you make a change (unless you make a change while it's running, then it will interrupt itself and run again). If it's manual then you have to press the button to run the playground.

如果您将鼠标悬停在按钮上,则会在按钮的底角出现一个黑色的小三角形。如果您长按按钮,将出现下面屏幕截图中的菜单,您可以在其中更改 Playground 的执行模式在自动或手动运行之间。如果它是自动的,那么每次进行更改时它都应该运行一次(除非您在运行时进行更改,否则它会自行中断并再次运行)。如果它是手动的,那么您必须按下按钮才能运行操场。

playground menu

游乐场菜单

While running the button is a hollow square, like a stop button on a VCR. Pressing it will stop the execution.

运行时按钮是一个空心方块,就像 VCR 上的停止按钮。按下它将停止执行。

stop

停止

When it's not running it is a blue triangle, like a play button on a VCR. Pressing it will run the playground.

当它不运行时,它是一个蓝色三角形,就像 VCR 上的播放按钮。按下它将运行操场。

play

玩

(Running Xcode 8.3)

(运行 Xcode 8.3)

回答by Gagandeep Gambhir

In Xcode 10.1 there is a "Run Playground" command in the "Editor" menu which can be accessed via the following keyboard shortcut:

在 Xcode 10.1 中,“Editor”菜单中有一个“Run Playground”命令,可以通过以下键盘快捷键访问:

Command+ Shift+ Enter

Command+ Shift+Enter

screenshot of menu showing Run Playground

显示 Run Playground 的菜单屏幕截图

回答by Mor4eza

in Xcode 10, just use command(?) + shift(??) + Enter(?)

在 Xcode 10 中,只需使用command(?) + shift(??) +Enter(?)

回答by HenryRootTwo

Same in Xcode 11: Cmd-Shift-Return

在 Xcode 11 中相同:Cmd-Shift-Return

回答by multitudes

As in Xcode version 10.2 the "Execute Playground" command in the "Editor" menu has been replaced by "Run Playground" and has a shortcut by default ?+ SHIFT+ ENTER

在 Xcode 10.2 版本中,“Editor”菜单中的“Execute Playground”命令已被“Run Playground”替换,并且默认有一个快捷方式?+ SHIFT+ENTER

The reason why it doesn't refresh when you enter the same command again, is because Playground is already running. You first need to stop the Playground by either clicking on the stop button or entering your own shortcut as I did.

当您再次输入相同的命令时它不会刷新的原因是因为 Playground 已经在运行。您首先需要通过单击停止按钮或像我一样输入您自己的快捷方式来停止 Playground。

To do so go in

这样做进去

Xcode > Preferences > Key Binding

Xcode > 首选项 > 键绑定

and look for "Stop Playground".

并寻找“停止游乐场”。

screenshot

截屏

Add the shortcut you would like to use clicking in the empty field on the right. I entered:

添加您要使用的快捷方式,单击右侧的空白字段。我进入了:

?+SHIFT+ >

?+ SHIFT+ >

In this way you can use the default shortcut to run the playground and you use the custom shortcut to stop it. Once stopped you can run it again.

通过这种方式,您可以使用默认快捷方式运行 Playground,并使用自定义快捷方式停止它。一旦停止,您可以再次运行它。

Here in the menu:

在菜单中:

screenshot

截屏