7

I downloaded the Swift languages's GuidedTour.playground.zip file from

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html

Unzip it as GuidedTour.playground, open it in Xcode 6.1.1, then the error message:

Error running playground.
Unable to find suitable target device.

I click OK button to close the error message window, get back to the playground with the title "A Swift Tour". There is no output for any of the embedded code there. And every time I try to edit any of the code, the error message will pop up again and again.

Some people on the web had the same problem and solved it by adding some devices under the menu Window -> Devices -> SIMULATORS. I did it, but the error keeps showing.

If I click File -> New -> Playground to create a testing playground, this error message will not appear, and the testing code will run.

A week ago, I had replaced the HDD in my Early 2008 iMac with a SSD (solid state disk), recovered the whole system to the SSD from my Time Machine backup. Everything looks good until I found out that Xcode begins to refuse to run the tutorial "A Swift Tour". Before the SSD replacement, Xcode would run it. This might be related?

Can
  • 8,502
  • 48
  • 57
AlvaPan
  • 519
  • 3
  • 12
  • 1
    HDD replacement is probably not the cause, but the re-installed Xcode instead. Double check Xcode menu > Preferences > Downloads. See if correct version of simulator is downloaded and installed – Raptor Jan 23 '15 at 06:43
  • Currently I have iPad 2 for iOS 8.1 simulator. I went to Preferences > Downloads to download iOS 7.1 Simulator and added more simulators for iOS 7.1 in Window > Devices, but the error message still popped up. So I deleted the whole Xcode, and reinstalled it, keeping only the simulator for iOS 8.1 so that the unnecessary Xcode components will not clutter my smaller solid state disk. – AlvaPan Jan 23 '15 at 07:25
  • 2
    I have solved this problem. I found out that I just added not enough simulators so that Xcode was unable to find suitable target device. After I added all the 10 simulators for iOS 8.1, the error is gone and the output appears. – AlvaPan Jan 25 '15 at 22:30
  • Please put this as answer. – Raptor Jan 28 '15 at 01:54
  • an easy way to reset the simulator is to use Fastlane tools snapshot app. http://fastlane.tools `snapshot reset_simulators` then restart xcode – BigB Sep 25 '15 at 02:42
  • Possible duplicate of [Error running playground. Unable to find suitable target device. (iOS Swift)](http://stackoverflow.com/questions/27939210/error-running-playground-unable-to-find-suitable-target-device-ios-swift) – Mihriban Minaz Dec 10 '15 at 13:38

5 Answers5

6

Thanks a lot for Raptor's kind response. I have solved this problem. I found out that I just added not enough simulators so that Xcode was unable to find suitable target device. After I added all the 10 simulators for iOS 8.1, the error is gone and the output appears.

At first, it seems that I will have to add all of them to make it work. Then after quite a few experiments by removing and adding some back and forth and restarting xcode, I cannot make sure exactly how many simulators are needed. Maybe 3 or 4.

AlvaPan
  • 519
  • 3
  • 12
  • 3
    As ridiculous as it seems, this is what worked for me as of Xcode 7 beta 2. Thanks for posting this! – GSnyder Jun 30 '15 at 15:24
  • Me too! Just adding a few of the simulators didn't do it, but I did the iPads last, so maybe it was one of them. – Zev Eisenberg Jul 01 '15 at 01:14
  • 2
    try this: (0) quit Xcode. (1) rename ~/Library/Developer/CoreSimulator/Devices to ~/Library/Developer/CoreSimulator/DevicesBackup. (2) create empty new folder ~/Library/Developer/CoreSimulator/Devices. (3) launch Xcode. In my case, the Xcode 7 re-launch auto-magically created one simulator for each possible device and iOS combination. – marc-medley Sep 28 '15 at 22:50
  • Specifically, the iPad Pro is required: http://stackoverflow.com/a/33461378/1148702 – Tim Arnold May 11 '17 at 18:41
  • (You could also dupe this radar to try to get this fixed: http://www.openradar.me/23719213 ) – Tim Arnold May 11 '17 at 18:42
6

playgrounds will run fine, assuming at least one of the following simulators are configured: iPhone 6, iPhone 6+, iPad Air, resizable iPhone, or resizable iPad.

Robin
  • 61
  • 1
  • 1
  • Great tip Robin! Don't know where you found this info, but I was almost pulling my hair out of my head. This saved my day/evening, thanks! – iOS-Coder Jul 08 '15 at 20:15
  • I spent a bit of time... Deleted all simulators, restarted Xcode. Created a single simulator, opened a playground to see if it would run. Deleted the single simulator, restarted Xcode, created the next simulator on the list, rinse & repeat. – Robin Jul 11 '15 at 14:43
  • adding an iPhone 6/ios 9 didn't work for me , adding an iPad Air ios9 did. Something freaky going on. – SimonTheDiver Oct 19 '15 at 08:22
4

At Xcode 7:

Step 1: Window > Devices > bottom left corner plus icon > add iPad Air or iPad Air 2.

Step 2: Quit and restart Xcode.

Ajeet Shah
  • 18,551
  • 8
  • 57
  • 87
Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
4

Delete the contents of ~/Library/Developer/XCPGDevices (typically it contains a directory with a name which is the UDID of the simulated device)

Muzahid
  • 5,072
  • 2
  • 24
  • 42
2

I am using Xcode Version 6.0.1. I reboot Mac (only restart Xcode didn't help) and this issue is resolved.

Hope this helps.

Ali
  • 121
  • 2
  • 5