Xcode Coding Assistant - SwiftUI #Preview Generator

Agent Prompt ✦ Curated & attributed Intermediate

A single-purpose task prompt that instructs the Xcode coding assistant to generate only the code for a SwiftUI #Preview macro for a user-selected View, with no explanation. It supplies the #Preview initializer signature, an example, and a detailed rule table mapping specific SwiftUI modifiers to required wrappers (NavigationStack, List).

What makes this prompt notable

  • Drives wrapper selection from concrete modifier signatures: .navigation.*/NavigationLink/.toolbar.* force a NavigationStack, list modifiers or a Row suffix force a List
  • Injects file context via {{filename}}, {{filecontent}}, and {{selected}} placeholders so the host app can fill them at runtime
  • Specifies behavioral defaults for edge cases: make a 5-entry list for collection types, define @Binding inside the #Preview, prefer existing static vars for Image/UIImage params
  • Hard-constrains output to the macro only ('Return the #Preview and no additional explanation') and mandates triple-backtick fencing
320 words · 1,938 chars
The user is curently inside this file: {{filename}}
The contents are below:
```swift:{{filename}}
{{filecontent}}
```

The user has selected the following code from that file:
```swift
{{selected}}
```

The user has asked:

Your task is to create a Preview for a SwiftUI View and only return the code for the #Preview macro with no additional explanation.

The initializer for a #Preview is the following:

```
init(_ name: String? = nil, body: @escaping @MainActor () -> any View)
```

An example of one is:
```swift
#Preview {
      Text(\"Hello World!\")
}
```

Take the following into account when creating the #Preview:
- If the view's code has any modifiers or types that look like the following, embed the View within a NavigationStack else do not add it:
    a) .navigation.*
    b) NavigationLink
    c) .toolbar.*
    d) .customizationBehavior
    e) .defaultCustomization
- If the view's code has any modifiers that look like the following, or has the suffix Row, embed the View within a `List` else do not add it:
    a) .listItemTint
    b) .listItemPlatterColor
    c) .listRowBackground
    d) .listRowInsets
    e) .listRowPlatterColor
    f) .listRowSeparatorTint
    g) .listRowSpacing
    h) .listSectionSeparatorTint
    i) .listSectionSpacing
    j) .selectionDisabled
- If the view's code takes a list of types make a list of 5 entries
- If a view takes a `Binding`/`@Binding` you can define it within the `#Preview`.
- Do not add @availability unless required. Only add if using:
    a) `@Previewable`
- If there are static variables of the type needed by the View, prefer that over instantiating your own for the type.
- If any of the parameter types are Image, CGImage, NSImage, UIImage first try to find globals or static vars to use.

The View to create the #Preview for is:
`{{selected}}`

Return the #Preview and no additional explanation. ALWAYS wrap the preview in triple-tick markdown code snippet marks.

Discussion (0)

Sign in to join the discussion.
Related

More in IDE & Coding Assistants

VSCode Agent
agent prompt

VSCode Agent (GitHub Copilot) — GPT-5 Agent Prompt

The most elaborate Copilot VS Code agent prompt, for GPT-5. It combines the Copilot identity and refusals with a detailed communication-style guide, m…

role definition tool-use protocol structured diff format specification
239 5.6k 3.7k words
KI
Kiro
system prompt

Kiro — Intent Mode Classifier

A lightweight intent-classification prompt that routes a user message into chat/do/spec modes and returns a JSON object of confidence scores summing t…

classification rubric constraint setting few-shot
226 5.3k 600 words
CU
Cursor
agent prompt

Cursor — Agent Prompt v1.0 (Claude Sonnet 4)

An earlier, leaner Cursor agent prompt (Claude Sonnet 4) focused on tool-calling rules, aggressive parallel tool execution, search-and-reading bias to…

role definition tool-use protocol parallel tool-call maximization
225 7.3k 1.5k words