# Get SwiftUI Previews Working on a Rented Mac

Canonical: https://figment.so/blog/mac-swiftui-previews-rented-mac

The canvas needs a graphical session, so use remote desktop, not SSH alone. Most "Preview update failed" errors clear with a clean build, a DerivedData reset or a preview simulator reset.

**SwiftUI Previews render inside Xcode's canvas, so you need a graphical macOS session on the rented Mac. A terminal alone is not enough.** Connect with remote desktop, open a SwiftUI file, and the canvas behaves as it does locally. The real work is clearing the "Preview update failed" errors that interrupt remote sessions, and the five common ones are below. Apple's authoring reference is [Previews in Xcode](https://developer.apple.com/documentation/swiftui/previews-in-xcode).

## Why can't I see previews over SSH alone?

The canvas is part of Xcode's GUI. Xcode manages a dedicated simulator device set (visible with `xcrun simctl --set previews list`) and talks to it through XPC, which needs a live window server. An SSH session has no window server, so `xcodebuild` can compile your SwiftUI code but no rendered frame can reach a terminal.

Open a remote desktop session to the Mac instead. Every Figment plan offers browser access to the Mac desktop and SSH. The Intel Mac VM and the Dedicated M4 Pro also offer encrypted remote desktop. If you turn on macOS Screen Sharing (VNC) yourself, do not expose it directly to the internet. Tunnel it through SSH:

```bash
ssh -N -L 5901:localhost:5900 user@YOUR_MAC_IP
# Connect your VNC client to localhost:5901
```

For a responsive canvas, aim for a round-trip latency under roughly 80 ms. Above that, resizing views and dragging parameter sliders becomes visibly sluggish. Work in a compact window and keep the canvas zoom at 100% or less.

Xcode's canvas needs horizontal space for both the editor and the preview pane. Apple does not publish a canvas minimum, so test your own project, but 1440 × 900 is a comfortable floor for keeping the canvas toggle and preview toolbar visible.

## How do I turn the canvas on?

Press `⌥⌘⏎` in a SwiftUI file to toggle the canvas.

1. Wait for the initial build. The canvas shows a spinner while Xcode compiles the preview.
2. If a "Preview update failed" banner appears, click **Diagnostics** in the banner. The log shows the real compiler or runtime error, not just the banner text.

## Why does my preview fail to update?

Work through these five causes in order. Each lists the symptom, the cause and the fix.

**1. Build error in an unrelated file**

*Symptom:* "Preview update failed" appears immediately, and Diagnostics names a module that is not the current file.

*Cause:* Previews need the whole module to build. A syntax error or type mismatch anywhere in the target blocks the preview build.

*Fix:* Run **Product → Build** (`⌘B`) and clear every error. The canvas will not render until the target builds cleanly.

**2. Corrupted DerivedData**

*Symptom:* Previews worked, then failed after an Xcode update or a large `git pull`. The log mentions a module interface version mismatch or a missing `.swiftmodule`.

*Cause:* Stale intermediate build products that do not match the current toolchain or source state.

*Fix:*

```bash
# Close Xcode first.
rm -rf ~/Library/Developer/Xcode/DerivedData
# Optional, for stuck module caches:
rm -rf ~/Library/Caches/com.apple.dt.Xcode
```

Reopen Xcode. The first preview after clearing DerivedData takes longer than usual.

**3. Stale preview simulators**

*Symptom:* The spinner runs indefinitely, Diagnostics shows a simulator boot timeout or "device not found", and restarting Xcode does not help.

*Cause:* The previews device set is in a bad state. A booted preview simulator crashed and left stale lock files.

*Fix:*

```bash
xcrun simctl --set previews delete all
```

Run this in Terminal.app inside the remote desktop session. Xcode recreates the preview device set the next time a preview is requested.

**4. Scheme or target mismatch**

*Symptom:* "Cannot preview in this file" or "Preview is unavailable for the current run destination", and the canvas is greyed out instead of showing a spinner.

*Cause:* The active scheme's run destination does not match the file being previewed, or the file belongs to a target that is not in the active scheme.

*Fix:* Change the run destination in the Xcode toolbar to an available simulator for the target platform. If the file belongs to a framework target, add that target under **Product → Scheme → Edit Scheme → Build**.

**5. Preview macro in the wrong target**

*Symptom:* The `#Preview` macro or `PreviewProvider` compiles, but the canvas shows "No preview provider found in this file".

*Cause:* The preview code is in a file assigned to a test target, and test targets are not compiled into the preview build.

*Fix:* In the File inspector (right sidebar, Target Membership), check the application or framework target, not the test target. If you need previews alongside tests, move the preview code into a preview-only file inside the main target.

## How do I keep the canvas responsive over a remote connection?

Reduce how many pixels and how much compilation each preview needs:

- **Reduce canvas zoom.** Click the zoom control at the bottom of the canvas and choose 50% or Fit. Fewer pixels per frame means less bandwidth.
- **Close unused editor panes.** A single editor plus canvas renders faster remotely than a split layout.
- **Prefer `#Preview` macros (Xcode 15+) over `PreviewProvider`.** The macro is more compact and is Apple's current recommendation. Measure your own project before claiming a build-speed gain.
- **Preview a subview, not the full screen.** Put the view you are editing in its own `#Preview` block with mock data, so the preview build recompiles only the changed file and its dependencies.

Multiple `#Preview` blocks in one file each appear as a named tab in the canvas. That helps when you cannot comfortably open several files side by side on a remote screen:

```swift
import SwiftUI

struct ProductCard: View {
    let title: String
    let price: Double

    var body: some View {
        VStack(alignment: .leading) {
            Text(title).font(.headline)
            Text(price, format: .currency(code: "USD"))
                .foregroundStyle(.secondary)
        }
        .padding()
        .background(.regularMaterial, in: RoundedRectangle(cornerRadius: 12))
    }
}

#Preview("In-stock item") {
    ProductCard(title: "Running Shoes", price: 129.99)
        .padding()
}

#Preview("Long title") {
    ProductCard(title: "Ultralight Carbon-Fiber Trail Running Shoes Pro Max",
                price: 299.00)
        .padding()
}
```

## What do I do when the canvas is blank and Diagnostics shows nothing?

Collect the preview subsystem log in Terminal.app on the rented Mac:

```bash
# If the predicate returns nothing on your Xcode version, drop it and grep the
# full stream for "preview" or "PreviewAgent".
log show \
  --predicate 'subsystem == "com.apple.dt.preview"' \
  --last 5m \
  --info \
  | tail -50
```

Also check crash reports for the preview agent:

```bash
ls ~/Library/Logs/DiagnosticReports/ | grep -i preview
```

Repeated `PreviewAgent` crashes usually recover with a two-step reset: delete DerivedData, run `xcrun simctl --set previews delete all`, then rebuild.

## Which Figment Mac plan fits SwiftUI previews?

Live previews are GUI and GPU work inside a virtual machine, and we have not measured preview rendering on any plan. For heavy canvas use, such as Metal-backed views, animations or large projects, the [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) is the safer choice ($349 a month, cancel any time), so test your own project in the first days. The [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) ($39 a month, $6 a day) runs current Xcode and suits lighter preview work. The Intel Mac VM runs macOS Sequoia and fits Xcode 26.3 or earlier only. See all [Mac hosting plans](/mac-hosting).

**Related guides:** [iOS SDK upgrade on a remote Mac](/blog/mac-ios-sdk-upgrade-remote-mac) · [Submit to TestFlight from a remote Mac](/blog/mac-testflight-submit-remote-mac) · [GitHub Actions self-hosted runner on Mac](/blog/mac-github-actions-self-hosted-runner)
