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

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' statement at the top of the screen with the loading icon promisingly spinning next to it but nothing happens. Sometimes this continues indefinitely and sometimes Xcode halts and prints this to console :

Playground execution failed: error: Couldn't lookup symbols:
__swift_FORCE_LOAD_$_swiftCoreImage 
__swift_FORCE_LOAD_$_swiftFoundation 
_playground_log_hidden 
_playground_logger_initialize 
_playground_log_postprint 

thread #1: tid = 0xc0cd0, 0x000000010ea7c3c0 MyPlayground`executePlayground, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2

frame #0: 0x000000010ea7c3c0 MyPlayground`executePlayground
frame #1: 0x000000010ea7b9c0 MyPlayground`__37-[XCPAppDelegate enqueueRunLoopBlock]_block_invoke + 32 
frame #2: 0x000000010f59625c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
frame #3: 0x000000010f57b304 CoreFoundation`__CFRunLoopDoBlocks + 356
frame #4: 0x000000010f57aa75 CoreFoundation`__CFRunLoopRun + 901
frame #5: 0x000000010f57a494 CoreFoundation`CFRunLoopRunSpecific + 420
frame #6: 0x0000000114985a6f GraphicsServices`GSEventRunModal + 161
frame #7: 0x0000000110124f34 UIKit`UIApplicationMain + 159
frame #8: 0x000000010ea7b6e9 MyPlayground`main + 201
frame #9: 0x0000000112ad268d libdyld.dylib`start + 1
frame #10: 0x0000000112ad268d libdyld.dylib`start + 1

I am running Xcode 8.0 (8A218a) on macOS Sierra 10.12.

Hardware:
MacBook Pro (13" Mid-2012)
2,5 GHz Intel Core i5
4 GB 1600 MHz Ram DDR3

I have looked around but at least neither of these threads have provided an answer:
https://forums.developer.apple.com/thread/5902
https://github.com/jas/playground/issues/9

Things I have already tried with zero success:

  • Restarting Xcode
  • Reinstalling Xcode (downgraded to 7.3 but since that didn't help I upgraded back to 8.0)
  • Restarting the machine
  • Creating a new playground

Do you have any ideas on how to solve this problem? I am new to programming and eagerly trying to learn Swift but Xcode is making it practically impossible...

Thank you in advance, cheers.


Solution 1:

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

Solution 2:

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

Solution 3:

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