<!--
{
  "availability" : [
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "DeveloperToolsSupport",
  "identifier" : "/documentation/DeveloperToolsSupport/Preview/init(_:traits:body:)-158mk",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "DeveloperToolsSupport"
    ],
    "preciseIdentifier" : "s:21DeveloperToolsSupport7PreviewV6AppKitE_6traits4bodyACSSSg_AA0D5TraitVyAC10ViewTraitsOGdSo6NSViewCyScMYcctcfc"
  },
  "title" : "init(_:traits:body:)"
}
-->

# init(_:traits:body:)

Creates a preview of an NSView.

```
@MainActor init(_ name: String? = nil, traits: PreviewTrait<Preview.ViewTraits>..., body: @escaping @MainActor () -> NSView)
```

## Discussion

The `#Preview` macro expands into a declaration that calls this initializer. To create a preview
that appears in the canvas, you must use the macro, not call this initializer directly.

---

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)