Xcode SwiftUI Preview Not Working or Crashing

Share
Ongoing macOS Updated November 13, 2026Based on 4 user reportsHow we research

Quick answer

Previews break when the project doesn't build, a dependency is missing, or the preview process crashes. Fix the build first, then restart the preview and clear its cache.

Most likely fix: Make the project build

How to fix it

Try these in order — the most common fix is first.

  1. 1. Make the project build

    1. Press Cmd-B and fix errors first; previews need a successful build
    Did this fix it?
  2. 2. Resume and rebuild the preview

    1. Press Option-Cmd-P to refresh
    2. Choose a different preview device in the canvas
    Did this fix it?
  3. 3. Clear preview data

    1. Quit Xcode
    2. Delete ~/Library/Developer/Xcode/UserData/Previews
    3. Delete the project's DerivedData and reopen
    Did this fix it?
  4. 4. Fix preview code

    1. Provide mock data and environment objects in the #Preview block
    2. Wrap code that needs a device in conditional checks
    Did this fix it?
  5. 5. Check the diagnostics

    1. Click the diagnostics button in the canvas and read the crash report
    Did this fix it?

Symptoms

The canvas shows 'Failed to build', 'Cannot preview in this file', or 'Preview crashed' and the Resume button does nothing.

Why it happens

  • The target does not build
  • Preview code uses unavailable types or missing environment objects
  • Corrupted preview cache
  • Wrong run destination selected

This guide also covers

  • swiftui preview not working
  • xcode preview crashed
  • xcode canvas failed to build

Still not working?

If Xcode keeps failing, you're not alone. See every Xcode problem users report or the alternatives people switch to.

Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.

Talk to us
Fixed it? Share this guide

Other Xcode errors

All 10 Xcode errors and fixes →