SwiftUI.cc
Fix
Fix

SwiftUI Preview Not Working: Causes & Fix

SwiftUI previews may fail to load or crash in Xcode, affecting developer workflow.

5 min readUpdated 2026-06

The Problem

When working with SwiftUI previews in Xcode, you might encounter a blank canvas, a crash, or an error like "Failed to render" or "Preview crashed":

// ❌ Wrong
import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

In some cases, the preview might work initially and then stop responding or crash repeatedly.

Root Cause

SwiftUI previews run in a separate process inside the Xcode canvas using the Simulator runtime. Issues can arise due to:

  • Simulator state corruption
  • Xcode cache inconsistencies
  • Incompatible dependencies or beta SDKs
  • Memory pressure or rendering bugs

This is often not a problem with your code, but with the preview system itself. The SwiftUI preview mechanism is sensitive to the environment state, and sometimes fails to reload properly after errors or crashes.

The Fix

A reliable way to reset the preview environment is to manually clean the build folder and restart related services:

// ✅ Fixed
import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Steps to fix:

  1. Clean the build folder (Product > Clean Build Folder or Shift + Command + K)
  2. Reset the simulator (Simulator > Device > Erase All Content and Settings)
  3. Restart Xcode
  4. Re-launch the preview (sometimes toggling the "Resume" button in the canvas helps)

Alternative Approaches

  • Use a physical device for preview: If simulator-based previews are unstable, try using a physical device for live preview (available in Xcode 13+).
  • Comment out complex preview code: Temporarily simplify or comment out complex preview content to isolate rendering issues.
  • Update Xcode: Ensure you are using the latest stable version of Xcode, as preview performance and stability improve with newer releases.

Affected iOS Versions

This issue is not tied to a specific iOS version but rather to the Xcode version and the SwiftUI rendering engine. It has been reported in Xcode 11 through Xcode 14. Apple has made incremental improvements to preview stability in Xcode 15 and Xcode 16, especially with the introduction of the new Preview API and improved diagnostics.

  • [swiftui-simultaneous-rotations-broken]
  • [swiftui-preview-multiple-previews-crash]
  • [swiftui-canvas-failed-to-render]