<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WidgetKit",
  "identifier" : "/documentation/WidgetKit/WidgetPreviewContext",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "WidgetKit"
    ],
    "preciseIdentifier" : "s:9WidgetKit0A14PreviewContextV"
  },
  "title" : "WidgetPreviewContext"
}
-->

# WidgetPreviewContext

A specification for the context of a widget preview.

```
struct WidgetPreviewContext
```

## Overview

To create a preview for a widget in Xcode, use
<doc://com.apple.documentation/documentation/SwiftUI/View/previewContext(_:)>
and pass `WidgetPreviewContext` initialized with the appropriate
`WidgetFamily`.

```
struct Widget_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            MyWidgetView()
                .previewContext(WidgetPreviewContext(family: .systemSmall))
        }
    }
}
```

## Topics

### Creating a Preview Context

[`init(family:)`](/documentation/WidgetKit/WidgetPreviewContext/init(family:))

Creates a context for previewing a widget or a widget’s view.



---

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)