7

Xcode 12.5 playgrounds don't seem to run any code at all, or display line by line outputs when ran. When I make a new playground, and click on any line of code to run, or try to run all the lines of code with the button at the bottom of the screen, I am shown in the top bar: "Build test (Playground): Succeeded" but there is no output in the command prompt, even when print statements are added, and there is no information in the side bar. I've tried:

  1. Restarting Xcode and rebooting my macbook
  2. Stopping the simulator via the Activity monitor and restarting it
  3. Opening up new tabs in an attempt to refresh
  4. Uninstalling and reinstalling Xcode via the app store
  5. Switching the playground settings for Platform from iOS to macOS

All to no avail. I've tried opening other playgrounds from downloaded files (e.g. the swift tutorial from apple's website) and they all give me the same results, which is opening the code but not displaying any results in the side bar or running the code.

I'm currently on an M1 Macbook Pro 2020, with 8gb of RAM, as well as MacOS version 11.4 Here is a picture of what I see

Edit: Changing whether the playground runs automatically does not affect the output of Xcode. Both automatic and manual result in not running any portion of the playground.

Jake
  • 96
  • 1
  • 6
  • 1
    Playgrounds is incredibly buggy... maybe just use Xcode instead. Or try downloading [Swift Playgrounds](https://www.apple.com/swift/playgrounds/). – aheze Jun 21 '21 at 06:51
  • https://stackoverflow.com/questions/34269297/how-do-you-prevent-xcode-7-playgrounds-from-automatically-running – Shadowrun Jun 21 '21 at 07:01
  • Does this answer your question? [How do you prevent Xcode 7 Playgrounds from automatically running?](https://stackoverflow.com/questions/34269297/how-do-you-prevent-xcode-7-playgrounds-from-automatically-running) – Abhishek Dutt Jun 21 '21 at 12:00

5 Answers5

7

Swift Playgounds don't work for me if Xcode 12 was launched in the "Open using Rosetta" mode.

Solution:

  1. Go to "Applications" folder -> Right click on the Xcode -> "Get Info" menu item

Get Info menu

  1. Unselect "Open using Rosetta" checkbox.

enter image description here

Close (Cmd+Q) Xcode and open it again. Next time it will be opened without Rosseta and playgrounds should work fine.

Petr Lazarev
  • 3,102
  • 1
  • 21
  • 20
6

Running Xcode 14.1 and macOS Ventura 13.0.1

Was struggling with this as well, fixed it:

  1. Go to playground settings on the right side
  2. Select macOS under platform

It's not perfect solution, but it works for now.

klaudas
  • 427
  • 5
  • 13
  • Switching back to iOS did not work for me, but at least I saw output for macOS, which was fine for my case. (Using Xcode 14.0) – Alex B Nov 30 '22 at 13:46
  • @AlexB yeah, I noticed that too after some time. But macOS is a temporary fix anyway. – klaudas Dec 01 '22 at 10:34
5

I was having this issue, changing in the Playground Setting in File inspector from iOS to macOS and you will have to use Foundation module instead of UIKit. I am using Xcode 12.5.1

Dharman
  • 30,962
  • 25
  • 85
  • 135
Leandro
  • 51
  • 1
  • 1
2

It seems like Xcode playgrounds seem to be completely broken (at least for my setup). For anyone else trying to learn swift that's experiencing this problem, instead of using playgrounds I created a new command line project in Xcode in order to run the Swift files. How to do this is outlined here: https://www.aidanf.net/learn-swift/running_code

Jake
  • 96
  • 1
  • 6
0

Two causes to this that I have seen.

  1. Xcode is opened with Rosetta checked.
  2. The build tools are not selected in Preferences > Locations > Command Line Tools:.

I've had the build tools magically deselect themselves for some reason. Rosetta was selected to allow certain pod files to build when the Simulator is targeted on an M1 Mac.

Xcode should fire off an error if there are no dev tools selected, but for some reason it doesn't do that and just displays nothing in the console and no error message at the top of the screen as it does for other errors.

Alex Zavatone
  • 4,106
  • 36
  • 54