Xcode playground gets stuck on 'Running playground' or 'Launching simulator' and won't run the code, what to do?

前端 未结 22 719
情歌与酒
情歌与酒 2020-12-22 16:03

Every time I create a new playground in order to test some code, Xcode gets stuck and won\'t run the code. It simply presents \'Running playground\' or \'Launching simulator

相关标签:
22条回答
  • 2020-12-22 16:18

    For me, the issue was the fact that MyPlayground was syncing to iCloud. Xcode saves your files every few seconds, and it leads to "not responding" states.

    So there is a simple solution- just go to:

    System Preferences - Apple ID - Apps on this Mac using iCloud- iCloud Drive - Options- And then uncheck "Playground"

    That little trick helps to solve frozen "Running".

    0 讨论(0)
  • 2020-12-22 16:20

    I have tried the following and it worked for me:

    1. press on the bottom "stop playground" button
    2. remove the first comment line and make import statement the first line. no space above import.
    3. press execute button
    0 讨论(0)
  • 2020-12-22 16:20

    Buggy Simulator's main process is still working even after Xcode closing. So here're the steps:

    1. Quit Xcode;
    2. Kill com.apple.CoreSimulator.CoreSimulatorService process in Activity Monitor;
    3. Launch Xcode and run your Playground.
    0 讨论(0)
  • 2020-12-22 16:21

    Ans. Switch to macOS platform

    When you create a Playground, by default it select iOS platform and automatically imports UIKit. It's the UIKit which crashes and stuck all the time. If your (practice) code does not use UIKit then you can switch to MacOS platform. As major (not exact though) difference between iOS and macOS is in APPKit and UIKit.

    In the upper right corner of your Xcode Playground, click on show/hide Utilities--> file inspector --> Playground Setting--> Platform--> macOS

    See screenShot below:

    0 讨论(0)
  • 2020-12-22 16:22

    Adding import PlaygroundSupport solved the problem for me :)

    0 讨论(0)
  • 2020-12-22 16:23

    In my case the problem was user-induced. I had the assistant editor displayed, but the live view wasn't selected. Make sure it looks like this:

    And not like this:

    0 讨论(0)
提交回复
热议问题