swiftui-patterns

Guide SwiftUI List and ForEach data sources with stable Hashable conformance.

Updated Oct 1, 2025
One-click install
npx skills add https://github.com/chmc/listall --skill swiftui-patterns-chmc
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-patterns
Source: https://github.com/chmc/listall/tree/main/.claude/skills/swiftui-patterns
Command: npx skills add https://github.com/chmc/listall --skill swiftui-patterns-chmc

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

SwiftUI patterns and antipatterns for List, ForEach, onMove, and data binding, enabling developers to diagnose issues and implement robust list-driven interfaces.

Core Features & Use Cases

  • Identify and correct common patterns for List and ForEach to maintain stable drag state and predictable UI updates.
  • Highlight typical antipatterns (e.g., using computed properties as data sources or unstable Hashable conformance) and show robust alternatives.
  • Use cases include debugging drag-and-drop in SwiftUI apps, implementing reliable item reordering, and ensuring consistent state across mutations.

Quick Start

Review the patterns and antipatterns below and apply the recommended List/ForEach strategies to your SwiftUI views.

Frequently Asked Questions about swiftui-patterns

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

FAQPage Schema
Why does my SwiftUI List drag-and-drop reorder crash or behave unstably?

Unstable SwiftUI List drag-and-drop behavior usually stems from using computed properties as data sources or unstable Hashable conformance. You must bind directly to a @Published array and ensure stable identifiers across mutations to maintain predictable UI updates.

How do I fix ForEach update timing issues when persisting reordered list items?

Fix ForEach update timing issues by applying correct async persistence patterns during onMove. Delay state mutations until persistence completes, ensuring consistent state across dynamic list updates and preventing UI desync.

What is the correct data source pattern for a SwiftUI List with onMove?

The correct data source pattern for a SwiftUI List with onMove requires an explicit @Published array bound directly to the view. Avoid computed properties as data sources to ensure stable drag state and reliable item reordering.

Can I use a computed property as the data source for a SwiftUI ForEach loop?

You should not use computed properties as data sources for SwiftUI ForEach loops. This common antipattern breaks drag state stability; instead, use a direct @Published array to maintain predictable UI updates.

How do I implement reliable item reordering in a dynamic SwiftUI list?

Implement reliable item reordering in dynamic SwiftUI lists by combining direct @Published arrays with stable Hashable conformance and correct async persistence timing. This avoids common antipatterns and ensures consistent state during mutations.