58

I'm working on an Xcode 7 Playground that has many things running at once. Whenever I make an edit, it refreshes, restarts what was running and runs through the entire code again. That crashes my playground around every 15 minutes. Is there a way to prevent playgrounds from automatically running whenever I make an edit?

BK15
  • 739
  • 1
  • 6
  • 11

2 Answers2

138

In the lower-left part of the Playground there's a right-facing blue arrow, looking like a "play" button.

Do a long click on this button and you will get two options: "Automatically Run" and "Manually Run".

Choose the latter to put the Playground is manual mode and start/stop its execution yourself by clicking on this button.

enter image description here


You can also trigger the code execution by making a custom shortcut to the "Execute Playground" Editor menu command.

Go to Xcode > Preferences... then go to Key Bindings, scroll down to Editor Menu for Playground and add a new shortcut of your choice by double-clicking in the right column in front of the Execute Playground command.

enter image description here

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    Wish there was a shortcut key combination for this as Cmd+R for running an app in regular Xcode mode – Pavel Gurov Jan 10 '16 at 13:26
  • 2
    @PaulGurov I've edited my answer with a solution for that. – Eric Aya Jan 10 '16 at 14:09
  • @PavelGurov See my answer using macOS shortcuts – Frederic Adda Apr 29 '18 at 06:49
  • You wouldn't happen to know of a way to make this a default for new playgrounds, would you? Automatic execution has been the source of much frustration for me (mostly since it kills my CPU) and I would love to disable it once instead of every time I create a new playground. – Kilian May 21 '18 at 23:09
12

Actually, you CAN map a shortcut for "Execute Playground" to Cmd+R.

Use macOS keyboard shortcuts, instead of Xcode's keybindings.

Go to System Preferences > Keyboard > Shortcuts,

and in App shortcuts, click on +.

Choose Xcode.app, and add a new shortcut for "Execute Playground" (you have to type precisely this!). Shortcuts 1

Then click on Add. Shortcuts 2

Now you can use this shortcut in Xcode. Xcode menu shortcut

And don't worry for conflicts (at least up to Xcode 9): Execute Playground is not available for standard Xcode projects, and Run is not active for Playgrounds.

Frederic Adda
  • 5,905
  • 4
  • 56
  • 71