One Logo Pool Ball
SwiftUI · IOS API REFERENCE

PreviewProvider

protocol · iOS 13.0+ · Deprecated in iOS 27.0 · SDK 27.1

@MainActor @preconcurrency protocol PreviewProvider : _PreviewProvider

A type that produces view previews in Xcode. > Important: You can use this protocol to define a preview manually, but you typically use a preview macro like ``Preview(_:body:)`` instead. You can create an Xcode preview by declaring a structure that conforms to the `PreviewProvider` protocol. Implement the required ``PreviewProvider/previews-swift.type.property`` computed property, and return the view to display: struct CircleImage_Previews: PreviewProvider { static var previews: some View { CircleImage() } } Xcode statically discovers preview providers in your project and generates previews for any providers currently open in the source editor. Xcode generates the preview using the current run destination as a hint for which device to display. For example, Xcode shows the following preview if you've selected an iOS target to run on the iPhone 12 Pro Max simulator: ![A screenshot of the Xcode canvas previewing a circular image on an iPhone in the portrait orientation.](PreviewProvider-1) When you create a new file (File > New > File) and choose the SwiftUI view template, Xcode automatically inserts a preview structure at the bottom of the file that you can configure. You can also create new preview structures in an existing SwiftUI view file by choosing Editor > Create Preview. Customize the preview's appearance by adding view modifiers, just like you do when building a custom ``View``. This includes preview-specific modifiers that let you control aspects of the preview, like the device orientation: struct CircleImage_Previews: PreviewProvider { static var previews: some View { CircleImage() .previewInterfaceOrientation(.landscapeLeft) } } ![A screenshot of the Xcode canvas previewing a circular image on an iPhone in the landscape left orientation.](PreviewProvider-2) For the complete list of preview customizations, see <doc:Previews-in-Xcode>. Xcode creates different previews for each view in your preview, so you can see variations side by side. For example, you might want to see a view's light and dark appearances simultaneously: struct CircleImage_Previews: PreviewProvider { static var previews: some View { CircleImage() CircleImage() .preferredColorScheme(.dark) } } Use a ``Group`` when you want to maintain different previews, but apply a single modifier to all of them: struct CircleImage_Previews: PreviewProvider { static var previews: some View { Group { CircleImage() CircleImage() .preferredColorScheme(.dark) } .previewLayout(.sizeThatFits) } } ![A screenshot of the Xcode canvas previewing a circular image twice, once with a light appearance and once with a dark appearance. Both previews take up only as much room as they need to fit the circular image.](PreviewProvider-3)

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

PreviewProvider.platform

Static protocol requirements cannot be called through an instance.

All SwiftUI types →