How it works
PreviewModifierContent is the opaque placeholder view that SwiftUI hands to a PreviewModifier so the modifier can wrap whatever preview it is attached to. When you write a PreviewModifier, its body(content:context:) method receives an instance of this type as its content argument, standing in for the actual preview that will be substituted at display time. You rarely name PreviewModifierContent directly — it surfaces through the Content associated type — but it is the thing you decorate to build a reusable preview environment, such as shared chrome, fixtures, or a configured context, that several previews can opt into.
Receive the placeholder through the content parameter
Inside a PreviewModifier, the body(content:context:) method is handed the preview as a PreviewModifierContent value. In Framed, that value arrives as the content parameter, and returning it (with modifiers applied) is what defines the wrapper. The type is opaque, so you treat content as a View rather than inspecting it.
Refer to it by the Content associated type, not its concrete name
PreviewModifier exposes the placeholder under the Content typealias, which is why body's signature reads func body(content: Content, ...). Writing Content keeps you decoupled from the concrete PreviewModifierContent struct while still naming exactly the value you will wrap.
Wrap the content by chaining ordinary view modifiers
Because PreviewModifierContent conforms to View, you build the shared environment by applying modifiers to content like any other view. Framed adds .padding(), a translucent .background(.yellow.opacity(0.3)), and a .clipShape(RoundedRectangle(cornerRadius: 12)) — every preview that adopts Framed inherits this same framing.
Return some View so the wrapper composes
body(content:context:) returns some View, letting you nest the placeholder inside additional containers or backgrounds before handing it back. Here the decorated content is returned directly, but you could embed it in a stack or apply environment values around it so the placeholder is positioned wherever the shared layout needs it.
Apply the wrapper at the preview site
A PreviewModifier reaches the placeholder only once it is attached to a view, which is where PreviewModifierContent gets bound to real content. In this demo Framed() is applied with .modifier(Framed()) on the Text("Hello, Preview!"), so that text becomes the content the modifier frames.
Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct PreviewModifierContentDemo: View {
struct Framed: PreviewModifier {
func body(content: Content, context: Void) -> some View {
content
.padding()
.background(.yellow.opacity(0.3))
.clipShape(RoundedRectangle(cornerRadius: 12))
}
}
var body: some View {
VStack(spacing: 16) {
Text("PreviewModifier applies a")
Text("shared wrapper to preview content")
.font(.headline)
Text("Hello, Preview!")
.modifier(Framed())
}
.padding()
}
}