All skills
avdlee avatar

/swiftui-expert-skill

@1e522cf

Use when writing, reviewing, or refactoring SwiftUI code for iOS or macOS, including state and `@Observable` data flow, view composition, resizable layouts, safe areas, display scale, performance, lists, environment, localization, animation, Liquid Glass, and API migration. Also use for iPhone Duo, foldable, or large-display layouts (`NavigationSplitView` on large displays, two-column reflow, foldable grids, `ArrangementView`, `ReservedRegion`), hinge effects, vertical bars, `@State` initialization or synthesized-property diagnostics, `@ContentBuilder` ambiguity, `reorderable` drag/drop, custom `AsyncImage` `URLSession`, swipe actions outside List, item-bound `alert`/`confirmationDialog`, `ToolbarOverflowMenu`, `AnimatableValues`, Document APIs (`Document`/`DocumentReader`), and Instruments `.trace` capture or analysis.

Use this Skill: https://skilld.dev/gh/avdlee/swiftui-agent-skill/swiftui-expert-skill

This session only. Nothing lands on disk.

referencesmodifier-patterns.md

≈633 tokens on demand. Your agent reads this file only when SKILL.md points to it.

SwiftUI Modifier and Identity Patterns

Use this reference when a modifier is conditional or when modifier composition changes a view's structural identity.

Avoid Conditional .if Modifiers

Do not create an @ViewBuilder extension that switches between transform(self) and self. Its branches produce different view types, so toggling the condition can replace the subtree, reset state, and break animations.

// AVOID
extension View {
    @ViewBuilder
    func `if`<Content: View>(
        _ condition: Bool,
        transform: (Self) -> Content
    ) -> some View {
        if condition { transform(self) } else { self }
    }
}

When two states describe the same view, keep one structural identity and vary the modifier's value:

Text("Hello")
    .foregroundStyle(isHighlighted ? .red : .primary)
    .opacity(isEnabled ? 1 : 0.5)

Use if when the branches genuinely represent different views or when content is truly optional. Do not silently refactor an existing .if modifier during unrelated work; call out the identity risk and keep the behavioral change focused.

Use AnyShapeStyle When Style Types Differ

Some ShapeStyle branches do not unify in a ternary. Preserve the view's identity by erasing the styles, not the view:

Text("Status")
    .foregroundStyle(
        isActive
            ? AnyShapeStyle(.primary)
            : AnyShapeStyle(.tint)
    )

AnyShapeStyle is an appropriate value-type eraser and does not have the structural-identity cost of AnyView. Add it only when the original ternary does not compile; many combinations involving Color, such as .yellow and .primary, already unify.

Prefer No-Effect Values for Visual State

For visibility or styling changes where the same view should retain state, prefer an always-present modifier with a no-effect value:

DetailsView()
    .opacity(isVisible ? 1 : 0)

Opacity keeps the view in layout and accessibility by default. Use conditional inclusion when hidden content should be removed from layout, interaction, or accessibility.

Checklist

  • Conditional styling changes modifier values instead of branching the whole view
  • Existing .if helpers are reported as focused identity risks, not rewritten incidentally
  • AnyShapeStyle is used only when different style types fail to unify
  • AnyView is not introduced to solve a modifier type mismatch
  • Visibility behavior intentionally accounts for layout, hit testing, and accessibility

Source: SKILL.md on GitHub

No alerts2d5 checks · Risk SAFE
  • Gen Agent Trust Hub2d

    The skill is a professional-grade assistant for SwiftUI development and performance profiling. It includes Python scripts to interface with the Xcode xctrace CLI for recording and analyzing Instruments traces. All identified code and instructions are consistent with its stated purpose and follow security best practices.

  • Socket2d

    No alerts

  • Snyk2d

    Risk: LOW · No issues

  • Runlayer6mo

    19 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 1e522cf. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 days ago
  • Performance
  • swiftui
  • ios
  • macos
  • instruments
  • state-management
  • view-composition
  • accessibility
  • animations

README badge

README badge for avdlee/swiftui-agent-skill/swiftui-expert-skill

Provides guidance for writing, reviewing, and refactoring SwiftUI code for iOS and macOS, including state management, view composition, performance optimization, and Instruments trace recording and analysis. Covers deprecated API detection, animation patterns, accessibility, and Liquid Glass adoption.

Generated from the current SKILL.md.

Does this skill work with both iOS and macOS?
Yes. The skill covers SwiftUI for both iOS and macOS, with dedicated reference sections for macOS-specific patterns like scenes, window styling, and views (HSplitView, Table, PasteButton).
Can this skill help me record and analyze Instruments traces?
Yes. The skill includes workflows to record traces via `record_trace.py` (with template selection for real devices vs simulators) and analyze them via `analyze_trace.py` to identify hangs, hitches, CPU hotspots, and excessive view updates.
Does this skill enforce a specific architecture pattern?
No. It focuses on correctness and performance without mandating MVVM, VIPER, or other architectural styles, though it encourages separating business logic from views for testability.
What does the skill do about deprecated APIs?
It consults `references/latest-apis.md` at the start of every task to identify and replace deprecated APIs with modern equivalents across iOS 15+ through iOS 26+, and gates version-specific APIs with `#available`.
Does this skill handle Liquid Glass effects?
Yes, but only when explicitly requested by the user. It includes guidance in `references/liquid-glass.md` for iOS 26+ Liquid Glass adoption with sensible fallbacks for earlier versions.

Generated from the current SKILL.md. These answers refresh after source changes.