Xcode SwiftUI Preview Not Working or Crashing
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. Make the project build
- Press Cmd-B and fix errors first; previews need a successful build
Did this fix it?2. Resume and rebuild the preview
- Press Option-Cmd-P to refresh
- Choose a different preview device in the canvas
Did this fix it?3. Clear preview data
- Quit Xcode
- Delete ~/Library/Developer/Xcode/UserData/Previews
- Delete the project's DerivedData and reopen
Did this fix it?4. Fix preview code
- Provide mock data and environment objects in the #Preview block
- Wrap code that needs a device in conditional checks
Did this fix it?5. Check the diagnostics
- 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 usOther Xcode errors
- Xcode Simulator Not Launching or Won't Boot
- Xcode 'Unable to Install' App Error
- Xcode 'No Profiles Found' Code Signing Error
- Xcode 'Failed to Register Bundle Identifier' Error
- Xcode Indexing Stuck or Taking Forever
- Xcode Doesn't Show My iPhone (Device Not Detected)
- Xcode Taking Too Much Storage (How to Free 50GB+)
- Xcode 'Build Failed' With No Clear Error