跳转至
Protocol

PreviewProvider

A protocol that generates previews on the right-hand side of Xcode.

Declaration

protocol PreviewProvider : \_PreviewProvider

Overview

Xcode statically discovers types that conform to the PreviewProvider protocol in your app, and generates previews for each provider it discovers.

For example, to have Xcode render a preview of a simple view:

struct ExampleView: View {
    var body: some View {
        Circle()
            .fill(Color.green)
    }
}

struct ExampleViewPreview: PreviewProvider {
    static var previews: some View {
        ExampleView()
    }

    static var platform: PreviewPlatform? {
        .iOS
    }
}
Preview provider example 1

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Type Property

platform The platform on which to run the provider.

platform The platform on which to run the provider.

previews Generates a collection of previews.


Associated Type

Previews The type to preview.