preview-data-generator

Generate SwiftUI sample data and #Preview variant matrices for Xcode canvas prototyping.

696|66|Updated Oct 29, 2025
One-click install
npx skills add https://github.com/rshankras/claude-code-apple-skills --skill preview-data-generator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: preview-data-generator
Source: https://github.com/rshankras/claude-code-apple-skills/tree/main/skills/generators/preview-data-generator
Command: npx skills add https://github.com/rshankras/claude-code-apple-skills --skill preview-data-generator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Hand-writing realistic preview data and multi-variant #Preview blocks for SwiftUI views is tedious, so most views only get a single happy-path preview that never exposes empty, error, dark-mode, or large-text layout bugs.

Core Features & Use Cases

  • Sample Data Generation: Creates a .preview namespace per model with realistic instances plus edge cases (empty, single item, long strings, missing images, large lists), reusing existing Model.fixture() factories when present.
  • Preview Matrix Generation: Emits #Preview blocks across data states (loaded/empty/loading/error), light/dark, Dynamic Type, locale/RTL, and device sizes, scaled to the view's complexity.
  • Modern API Support: Detects the deployment target and uses #Preview macros, PreviewModifier for cached shared data, @Previewable for state, seeded in-memory SwiftData containers, or PreviewProvider fallbacks for older targets.
  • Use Case: You have an ArticleListView backed by SwiftData and want to prototype it. The skill generates Article+Preview.swift with edge-case data, a cached PreviewModifier with a seeded in-memory container, and seven #Preview variants covering all states, dark mode, XXL text, and German localization.

Quick Start

Ask the AI to add previews with sample data for your SwiftUI view, covering empty, loading, error, and loaded states plus dark mode and large Dynamic Type.

Frequently Asked Questions about preview-data-generator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add sample data to SwiftUI previews?

Create a `.preview` static property in a #if DEBUG extension on your model with a realistic instance, then add edge-case variants like long titles, missing images, and empty lists. Reference these in #Preview blocks so the Xcode canvas renders meaningful data.

How do I preview a SwiftUI view in empty, loading, and error states?

Drive each state through whatever the view reads: pass a state enum directly, inject a pinned ViewModel instance, or seed an in-memory SwiftData container. Generate one #Preview block per state so all variants appear side by side in the canvas.

What is PreviewModifier in Xcode 16 and when should I use it?

PreviewModifier is an iOS 18 / Xcode 16 API that builds shared preview context once and caches it across every preview. Use it when multiple previews need the same expensive setup, such as a seeded SwiftData container, via #Preview(traits: .modifier(SampleData())).

How do I preview a SwiftData view without touching the real database?

Create a ModelContainer with ModelConfiguration(isStoredInMemoryOnly: true), insert sample models into its mainContext, and attach it with .modelContainer(previewContainer). The in-memory store never persists or touches production data.

Does #Preview work on iOS 16 or earlier deployment targets?

No, the #Preview macro requires iOS 17 or later. For earlier targets, use the PreviewProvider struct with previewDisplayName and modifiers like preferredColorScheme to achieve the same variant matrix.

When should I use test fixtures instead of preview sample data?

Test fixtures belong in the unit test suite and optimize for minimal assertion-friendly objects, while preview data optimizes for visual stress cases. If a fixture factory already exists, build preview data on top of it rather than duplicating field definitions.