SwiftUI preview failed to launch app in reasonable time in Xcode 12.4

I am trying to get started with SwiftUI but whenever I try to start the preview window I see a spinner for a minute or more ( it's currently been spinning for around 10 minutes ) followed by the message Failed to launch app "myApp.app" in reasonable time. The app only contains an Image and a couple of ToolbarItems, there's no logic there yet and the spinner keeps on spinning long after the build is complete.

Clicking on Diagnostics gives little more information:
Code Block
AppLaunchTimeoutError: Failed to launch app "myApp.app" in reasonable time
The app "myApp.app" did not launch on "iPhone 11" in 15 seconds.

Things I have tried:
  • Cleaning and rebuilding.

  • Excluding the arm64 build target.

  • Changing the target device.

  • Using xcrun simctl shutdown all followed by scrub simctl erase all ( although this does seem to cause it to fail more quickly )

  • Clearing the contents of my ~/Library/Xcode/UserData/Previews folder.

At some point trying all of these something did work because I was briefly able to use it, but the next time I restarted the problem was back. If I run the app in the emulator it does load but also takes a very long time to start.

I'm using Xcode 12.4 on Big Sur.

Sorry to hear you are having problems getting previews working.


Based upon your description of the situation I am guessing that maybe there is something ending up in the app's data container that is causing the problem. To start from a fresh slate you can use the terminal app and run xcrun simctl --set previews delete all.

If that still doesn't resolve issue then probably best next step will be to file a feedback with diagnostics.
We will need the diagnostics Xcode Previews generates in order to make sure we understand the error the previews system is encountering.
  1. When you get an error in Xcode Previews, an error banner appears in the canvas

  2. Click the "Diagnostics" button in that banner

  3. In the sheet that appears, click "Generate Report" in the bottom left of the sheet

  4. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)

Then report back here with your feedback ID and I can make sure it gets to the right folks as soon as possible.
Thank you for this. The delete all command does work, but I have to run it every time I resume the preview or I run into the same problem, which feels a little wrong.
I now think that my actions had no effect but the preview system is taking 30-45 minutes to start, and I was assuming that whatever I was doing was having an effect, then the next day I started with that and it didn't work, because the only thing that was working was waiting for an incredibly long time. I have created a Feedback item at FB8988812.
I had the same problem, even after restarting the entire system. I quit Xcode, deleted Derived Data, and then things worked.
For those who have never deleted derived data, here's a primer:
  • > This is a url: -> deriveddata.dance

Curiously, when I tried the suggestion above:
xcrun simctl --set previews delete all.
Output states:
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH

I know I had previously had command-line tools on this machine. Is there something I'm missing or need to reinstall? Thanks!
SwiftUI preview failed to launch app in reasonable time in Xcode 12.4
 
 
Q