Home Guides SwiftUI code preview

A SwiftUI code preview that runs

A SwiftUI code preview, in Swoop, is the stage. The phone 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 on the phone.

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 iPhone, 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.

Keep going

Get Swoop

iPhone. iOS 17 and later. The file plays on the phone.