<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WidgetKit",
  "identifier" : "/documentation/WidgetKit/Preview(_:as:using:widget:contentStates:)",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "WidgetKit"
    ],
    "preciseIdentifier" : "s:9WidgetKit7Preview_2as5using6widget13contentStatesySSSg_AA08ActivityC8ViewKindOq_xycSay12ContentStateQy_GyYaScMYcctc7SwiftUI0A0Rz0iB00I10AttributesR_r0_lufm"
  },
  "title" : "Preview(_:as:using:widget:contentStates:)"
}
-->

# Preview(_:as:using:widget:contentStates:)

Preview a widget with an activity configuration, using the specified attributes and content states.

```
@freestanding(declaration) macro Preview<Widget, Attributes>(_ name: String? = nil, as viewKind: ActivityPreviewViewKind, using attributes: Attributes, widget: @escaping () -> Widget, @PreviewActivityBuilder<Attributes> contentStates: @escaping @MainActor () async -> [Attributes.ContentState]) where Widget : Widget, Attributes : ActivityAttributes
```

## Parameters

`name`

An optional display name for the preview that appears in the preview canvas.

`viewKind`

The kind of widget view to display.

`attributes`

The attributes with which to configure the widget.

`widget`

A closure producing the widget to be previewed.

`contentStates`

A closure building the content states to be previewed.

## Overview

Provide the preview with sample data and use it to step through the specified content states and test out the transitions between them.

> Note: The attributes must be of the type that the widget expects.

---

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)