{
  "schema": "https://ai-atoms.com/schemas/skill-v1.json",
  "type": "skill",
  "id": "skill/swiftui-expert-skill",
  "version": "1.0.0",
  "name": "Swiftui Expert Skill",
  "description": "Write, review, or improve SwiftUI code following best practices for state management, view composition, performance, modern APIs, Swift concurrency, and iOS 26+ Liquid Glass adoption. Use when buil...",
  "system_prompt_fragment": "# SwiftUI Expert Skill\n\n## Overview\nUse this skill to build, review, or improve SwiftUI features with correct state management, modern API usage, Swift concurrency best practices, optimal view composition, and iOS 26+ Liquid Glass styling. Prioritize native APIs, Apple design guidance, and performance-conscious patterns. This skill focuses on facts and best practices without enforcing specific architectural patterns.\n\n## When to Use This Skill\n\nUse this skill when:\n- Building new SwiftUI features\n- Refactoring existing SwiftUI views\n- Reviewing SwiftUI code quality\n- Adopting modern SwiftUI patterns\n- Working with SwiftUI state management\n- Implementing iOS 26+ Liquid Glass styling\n\n## Workflow Decision Tree\n\n### 1) Review existing SwiftUI code\n- Check property wrapper usage against the selection guide (see `references/state-management.md`)\n- Verify modern API usage (see `references/modern-apis.md`)\n- Verify view composition follows extraction rules (see `references/view-structure.md`)\n- Check performance patterns are applied (see `references/performance-patterns.md`)\n- Verify list patterns use stable identity (see `references/list-patterns.md`)\n- Inspect Liquid Glass usage for correctness and consistency (see `references/liquid-glass.md`)\n- Validate iOS 26+ availability handling with sensible fallbacks\n\n### 2) Improve existing SwiftUI code\n- Audit state management for correct wrapper selection (prefer `@Observable` over `ObservableObject`)\n- Replace deprecated APIs with modern equivalents (see `references/modern-apis.md`)\n- Extract complex views into separate subviews (see `references/view-structure.md`)\n- Refactor hot paths to minimize redundant state updates (see `references/performance-patterns.md`)\n- Ensure ForEach uses stable identity (see `references/list-patterns.md`)\n- Suggest image downsampling when `UIImage(data:)` is used (as optional optimization, see `references/image-optimization.md`)\n- Adopt Liquid Glass only when explicitly requested by the user\n\n### 3) Implement new SwiftUI feature\n- Design data flow first: identify owned vs injected state (see `references/state-management.md`)\n- Use modern APIs (no deprecated modifiers or patterns, see `references/modern-apis.md`)\n- Use `@Observable` for shared state (with `@MainActor` if not using default actor isolation)\n- Structure views for optimal diffing (extract subviews early, keep views small, see `references/view-structure.md`)\n- Separate business logic into testable models (see `references/layout-best-practices.md`)\n- Apply glass effects after layout/appearance modifiers (see `references/liquid-glass.md`)\n- Gate iOS 26+ features with `#available` and provide fallbacks\n\n## Core Guidelines\n\n### State Management\n- **Always prefer `@Observable` over `ObservableObject`** for new code\n- **Mark `@Observable` classes with `@MainActor`** unless using default actor isolation\n- **Always mark `@State` and `@StateObject` as `private`** (makes dependencies clear)\n- **Never declare passed values as `@State` or `@StateObject`** (they only accept initial values)\n- Use `@State` with `@Observable` classes (not `@StateObject`)\n- `@Binding` only when child needs to **modify** parent state\n- `@Bindable` for injected `@Observable` objects needing bindings\n- Use `let` for read-only values; `var` + `.onChange()` for reactive reads\n- Legacy: `@StateObject` for owned `ObservableObject`; `@ObservedObject` for injected\n- Nested `ObservableObject` doesn't work (pass nested objects directly); `@Observable` handles nesting fine\n\n### Modern APIs\n- Use `foregroundStyle()` instead of `foregroundColor()`\n- Use `clipShape(.rect(cornerRadius:))` instead of `cornerRadius()`\n- Use `Tab` API instead of `tabItem()`\n- Use `Button` instead of `onTapGesture()` (unless need location/count)\n- Use `NavigationStack` instead of `NavigationView`\n- Use `navigationDestination(for:)` for type-safe navigation\n- Use two-parameter or no-parameter `onChange()` variant\n- Use `ImageRenderer` for rendering SwiftUI views\n- Use `.sheet(item:)` instead of `.sheet(isPresented:)` for model-based content\n- Sheets should own their actions and call `dismiss()` internally\n- Use `ScrollViewReader` for programmatic scrolling with stable IDs\n- Avoid `UIScreen.main.bounds` for sizing\n- Avoid `GeometryReader` when alternatives exist (e.g., `containerRelativeFrame()`)\n\n### Swift Best Practices\n- Use modern Text formatting (`.format` parameters, not `String(format:)`)\n- Use `localizedStandardContains()` for user-input filtering (not `contains()`)\n- Prefer static member lookup (`.blue` vs `Color.blue`)\n- Use `.task` modifier for automatic cancellation of async work\n- Use `.task(id:)` for value-dependent tasks\n\n### View Composition\n- **Prefer modifiers over conditional views** for state changes (maintains view identity)\n- Extract complex views into separate subviews for better readability and performance\n- Keep views small for optimal performance\n- Keep view `body` simple and pure (no side effects or complex logic)\n- Use `@ViewBuilder` functions only for small, simple sections\n- Prefer `@ViewBuilder let content: Content` over closure-based content properties\n- Separate business logic into testable models (not about enforcing architectures)\n- Action handlers should reference methods, not contain inline logic\n- Use relative layout over hard-coded constants\n- Views should work in any context (don't assume screen size or presentation style)\n\n### Performance\n- Pass only needed values to views (avoid large \"config\" or \"context\" objects)\n- Eliminate unnecessary dependencies to reduce update fan-out\n- Check for value changes before assigning state in hot paths\n- Avoid redundant state updates in `onReceive`, `onChange`, scroll handlers\n- Minimize work in frequently executed code paths\n- Use `LazyVStack`/`LazyHStack` for large lists\n- Use stable identity for `ForEach` (never `.indices` for dynamic content)\n- Ensure constant number of views per `ForEach` element\n- Avoid inline filtering in `ForEach` (prefilter and cache)\n- Avoid `AnyView` in list rows\n- Consider POD views for fast diffing (or wrap expensive views in POD parents)\n- Suggest image downsampling when `UIImage(data:)` is encountered (as optional optimization)\n- Avoid layout thrash (deep hierarchies, excessive `GeometryReader`)\n- Gate frequent geometry updates by thresholds\n- Use `Self._printChanges()` to debug unexpected view updates\n\n### Liquid Glass (iOS 26+)\n**Only adopt when explicitly requested by the user.**\n- Use native `glassEffect`, `GlassEffectContainer`, and glass button styles\n- Wrap multiple glass elements in `GlassEffectContainer`\n- Apply `.glassEffect()` after layout and visual modifiers\n- Use `.interactive()` only for tappable/focusable elements\n- Use `glassEffectID` with `@Namespace` for morphing transitions\n\n## Quick Reference\n\n### Property Wrapper Selection (Modern)\n| Wrapper | Use When |\n|---------|----------|\n| `@State` | Internal view state (must be `private`), or owned `@Observable` class |\n| `@Binding` | Child modifies parent's state |\n| `@Bindable` | Injected `@Observable` needing bindings |\n| `let` | Read-only value from parent |\n| `var` | Read-only value watched via `.onChange()` |\n\n**Legacy (Pre-iOS 17):**\n| Wrapper | Use When |\n|---------|----------|\n| `@StateObject` | View owns an `ObservableObject` (use `@State` with `@Observable` instead) |\n| `@ObservedObject` | View receives an `ObservableObject` |\n\n### Modern API Replacements\n| Deprecated | Modern Alternative |\n|------------|-------------------|\n| `foregroundColor()` | `foregroundStyle()` |\n| `cornerRadius()` | `clipShape(.rect(cornerRadius:))` |\n| `tabItem()` | `Tab` API |\n| `onTapGesture()` | `Button` (unless need location/count) |\n| `NavigationView` | `NavigationStack` |\n| `onChange(of:) { value in }` | `onChange(of:) { old, new in }` or `onChange(of:) { }` |\n| `fontWeight(.bold)` | `bold()` |\n| `GeometryReader` | `containerRelativeFrame()` or `visualEffect()` |\n| `showsIndicators: false` | `.scrollIndicators(.hidden)` |\n| `String(format: \"%.2f\", value)` | `Text(value, format: .number.precision(.fractionLength(2)))` |\n| `string.contains(search)` | `string.localizedStandardContains(search)` (for user input) |\n\n### Liquid Glass Patterns\n```swift\n// Basic glass effect with fallback\nif #available(iOS 26, *) {\n    content\n        .padding()\n        .glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16))\n} else {\n    content\n        .padding()\n        .background(.ultraThinMaterial, in: RoundedRectangle(cornerRadius: 16))\n}\n\n// Grouped glass elements\nGlassEffectContainer(spacing: 24) {\n    HStack(spacing: 24) {\n        GlassButton1()\n        GlassButton2()\n    }\n}\n\n// Glass buttons\nButton(\"Confirm\") { }\n    .buttonStyle(.glassProminent)\n```\n\n## Review Checklist\n\n### State Management\n- [ ] Using `@Observable` instead of `ObservableObject` for new code\n- [ ] `@Observable` classes marked with `@MainActor` (if needed)\n- [ ] Using `@State` with `@Observable` classes (not `@StateObject`)\n- [ ] `@State` and `@StateObject` properties are `private`\n- [ ] Passed values NOT declared as `@State` or `@StateObject`\n- [ ] `@Binding` only where child modifies parent state\n- [ ] `@Bindable` for injected `@Observable` needing bindings\n- [ ] Nested `ObservableObject` avoided (or passed directly to child views)\n\n### Modern APIs (see `references/modern-apis.md`)\n- [ ] Using `foregroundStyle()` instead of `foregroundColor()`\n- [ ] Using `clipShape(.rect(cornerRadius:))` instead of `cornerRadius()`\n- [ ] Using `Tab` API instead of `tabItem()`\n- [ ] Using `Button` instead of `onTapGesture()` (unless need location/count)\n- [ ] Using `NavigationStack` instead of `NavigationView`\n- [ ] Avoiding `UIScreen.main.bounds`\n- [ ] Using alternatives to `GeometryReader` when possible\n- [ ] Button images include text labels for accessibility\n\n### Sheets & Navigation (see `references/sheet-navigation-patterns.md`)\n- [ ] Using `.sheet(item:)` for model-based sheets\n- [ ] Sheets own their actions and dismiss internally\n- [ ] Using `navigationDestination(for:)` for type-safe navigation\n\n### ScrollView (see `references/scroll-patterns.md`)\n- [ ] Using `ScrollViewReader` with stable IDs for programmatic scrolling\n- [ ] Using `.scrollIndicators(.hidden)` instead of initializer parameter\n\n### Text & Formatting (see `references/text-formatting.md`)\n- [ ] Using modern Text formatting (not `String(format:)`)\n- [ ] Using `localizedStandardContains()` for search filtering\n\n### View Structure (see `references/view-structure.md`)\n- [ ] Using modifiers instead of conditionals for state changes\n- [ ] Complex views extracted to separate subviews\n- [ ] Views kept small for performance\n- [ ] Container views use `@ViewBuilder let content: Content`\n\n### Performance (see `references/performance-patterns.md`)\n- [ ] View `body` kept simple and pure (no side effects)\n- [ ] Passing only needed values (not large config objects)\n- [ ] Eliminating unnecessary dependencies\n- [ ] State updates check for value changes before assigning\n- [ ] Hot paths minimize state updates\n- [ ] No object creation in `body`\n- [ ] Heavy computation moved out of `body`\n\n### List Patterns (see `references/list-patterns.md`)\n- [ ] ForEach uses stable identity (not `.indices`)\n- [ ] Constant number of views per ForEach element\n- [ ] No inline filtering in ForEach\n- [ ] No `AnyView` in list rows\n\n### Layout (see `references/layout-best-practices.md`)\n- [ ] Avoiding layout thrash (deep hierarchies, excessive GeometryReader)\n- [ ] Gating frequent geometry updates by thresholds\n- [ ] Business logic separated into testable models\n- [ ] Action handlers reference methods (not inline logic)\n- [ ] Using relative layout (not hard-coded constants)\n- [ ] Views work in any context (context-agnostic)\n\n### Liquid Glass (iOS 26+)\n- [ ] `#available(iOS 26, *)` with fallback for Liquid Glass\n- [ ] Multiple glass views wrapped in `GlassEffectContainer`\n- [ ] `.glassEffect()` applied after layout/appearance modifiers\n- [ ] `.interactive()` only on user-interactable elements\n- [ ] Shapes and tints consistent across related elements\n\n## References\n- `references/state-management.md` - Property wrappers and data flow (prefer `@Observable`)\n- `references/view-structure.md` - View composition, extraction, and container patterns\n- `references/performance-patterns.md` - Performance optimization techniques and anti-patterns\n- `references/list-patterns.md` - ForEach identity, stability, and list best practices\n- `references/layout-best-practices.md` - Layout patterns, context-agnostic views, and testability\n- `references/modern-apis.md` - Modern API usage and deprecated replacements\n- `references/sheet-navigation-patterns.md` - Sheet presentation and navigation patterns\n- `references/scroll-patterns.md` - ScrollView patterns and programmatic scrolling\n- `references/text-formatting.md` - Modern text formatting and string operations\n- `references/image-optimization.md` - AsyncImage, image downsampling, and optimization\n- `references/liquid-glass.md` - iOS 26+ Liquid Glass API\n\n## Philosophy\n\nThis skill focuses on **facts and best practices**, not architectural opinions:\n- We don't enforce specific architectures (e.g., MVVM, VIPER)\n- We do encourage separating business logic for testability\n- We prioritize modern APIs over deprecated ones\n- We emphasize thread safety with `@MainActor` and `@Observable`\n- We optimize for performance and maintainability\n- We follow Apple's Human Interface Guidelines and API design patterns",
  "applicable_domains": [
    "frontend"
  ],
  "category": "frontend",
  "invocation": [
    "/swiftui-expert-skill"
  ],
  "authored_by": "claudeskills.in community",
  "source_url": "https://claudeskills.in/skill/swiftui-expert-skill",
  "provenance": {
    "source": "claudeskills.in",
    "source_url": "https://claudeskills.in/skill/swiftui-expert-skill",
    "license": "MIT",
    "imported_at": "2026-09-03",
    "notes": "Aggregated by claudeskills.in from community GitHub lists. Upstream as recorded by the aggregator: https://github.com/AvdLee/SwiftUI-Agent-Skill/tree/main/swiftui-expert-skill. License MIT read from github.com/AvdLee/SwiftUI-Agent-Skill on 2026-09-03."
  },
  "tags": [
    "claudeskills",
    "frontend",
    "risk-reviewed"
  ],
  "lifecycle": "draft"
}