Home Guides SwiftUI code preview

A SwiftUI code preview that runs

A SwiftUI code preview, in Swoop, is the stage. Swoop runs the file. It does not draw a lookalike, and it is not Xcode’s canvas.

A sketch of the stage. Nothing on this page is executing Swift. The file below plays live in Swoop.

What preview means here

People look this up when they want to see SwiftUI without a round trip through a build. On a Mac, that job belongs to Xcode. On your Mac, Swoop plays a subset of the same language: text, shapes, stacks, timelines, and springs.

If a line is outside that subset, or if Swift itself would reject it, play stops and names the line. You do not get a picture of something that would fail in Xcode. That is the whole point of the stage. The list of what plays is on the home page, next to a file that runs as written.

The file the stage runs

import SwiftUI

struct MintBadge: View {
    var body: some View {
        VStack(spacing: 8) {
            Circle()
                .fill(.mint)
                .frame(width: 36, height: 36)
            Text("Live")
                .font(.title)
                .foregroundStyle(.mint)
        }
    }
}

A circle, a word, a stack. Press play and that is what fills the stage. Copy hands you this source, not a translation of it. Paste it into a project that targets iOS 17 or later.

When the preview refuses

A refusal is a result, not a crash. The usual causes are a view the player does not implement, or a value of the wrong type, such as Text given a number. Send the file to support if something inside the subset stops and you think it should not. That is the useful bug report.

Why is my Xcode preview not showing?

An Xcode preview usually does not show because the canvas is hidden or the project does not build, and Swoop sidesteps both by running a single SwiftUI file with no project. In Xcode, open the canvas with Editor → Canvas (Option-Command-Return), fix any build errors in the scheme, and make sure the file has a #Preview or PreviewProvider. In Swoop there is no canvas to open: press Run and the file plays, or Swoop names the line it cannot play.

Keep going

Download Swoop for MacLifetime Pro

Free. macOS 14 or later, Apple silicon or Intel. The file plays live in Swoop.