Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

ios

xcode8

People also ask

Why is my Xcode playground not running?

Restarting Xcode and rebooting my macbook. Stopping the simulator via the Activity monitor and restarting it. Opening up new tabs in an attempt to refresh. Uninstalling and reinstalling Xcode via the app store.

What is the difference between playground and Xcode?

An Xcode project allows you to create real apps that you could eventually upload to the App Store (providing you became an Apple Developer). An Xcode Playground allows you to play with code and test it out. It isn't for mainstream developing.

What is the difference between Swift playground and Xcode?

Xcode and Swift are both software development products developed by Apple. Swift is a programming language used to create apps for iOS, macOS, tvOS, and watchOS. Xcode is an Integrated Development Environment (IDE) that comes with a set of tools that helps you build Apple-related apps.


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: enter image description here


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

In my case, Xcode 8.3.2, it works when I try as steps below:

  1. File -> Close "Name.playground"
  2. File -> Close Playground
  3. Quit Xcode
  4. Re-open Xcode

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.

In my experience, you should:

  1. Prevent Swift playground refresh, by holding: the ► arrow at the bottom left part of the Playground and selecting "Manually Run"
  2. Quit Xcode
  3. Restart Xcode

It works very well.