<!--
{
  "availability" : [
    "iOS: 13.0.0 - 27.0.0",
    "iPadOS: 13.0.0 - 27.0.0",
    "macCatalyst: 13.0.0 - 27.0.0",
    "macOS: 10.15.0 - 27.0.0",
    "tvOS: 13.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 6.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/PreviewProvider",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI15PreviewProviderP"
  },
  "title" : "PreviewProvider"
}
-->

# PreviewProvider

A type that produces view previews in Xcode.

```
@MainActor @preconcurrency protocol PreviewProvider : _PreviewProvider
```

## Overview> Important: You can use this protocol to define a preview manually, but
> you typically use a preview macro like ``doc://com.apple.SwiftUI/documentation/SwiftUI/Preview(_:body:)`` instead.

You can create an Xcode preview by declaring a structure that conforms to
the `PreviewProvider` protocol. Implement the required
[`previews`](/documentation/SwiftUI/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](images/com.apple.SwiftUI/PreviewProvider-1@2x.png)

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`](/documentation/SwiftUI/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](images/com.apple.SwiftUI/PreviewProvider-2@2x.png)

For the complete list of preview customizations,
see [Previews in Xcode](/documentation/SwiftUI/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`](/documentation/SwiftUI/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,](images/com.apple.SwiftUI/PreviewProvider-3@2x.png)

## Topics

### Creating a preview

[`previews`](/documentation/SwiftUI/PreviewProvider/previews-swift.type.property)

A collection of views to preview.

[`Previews`](/documentation/SwiftUI/PreviewProvider/Previews-swift.associatedtype)

The type to preview.

### Specifying the platform

[`platform`](/documentation/SwiftUI/PreviewProvider/platform)

The platform on which to run the provider.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)