data-flow
БесплатноБез исполняемых скриптовНе проверенSwiftUI's actual mental model — view identity, lifetime, and dependencies (the Demystify canon), state ownership decision rules, Observation's per-property…
от rshankras★ 922 звезды на GitHubОб этом скилле
SwiftUI Data Flow
Nearly every confusing SwiftUI bug — state that resets, animations that crossfade instead of
move, lists that flash, bodies that run constantly — traces to identity, lifetime, or
dependencies. This is Apple's own mental model (the Demystify sessions + Data Essentials +
Observation), current through the WWDC26 @State macro.
When This Skill Activates
- "@State resets when…" / state loses its value on a condition change
- Views re-render too often; animations crossfade when they should move
- Lists flashing, rows reordering wrongly,
ForEachmisbehaving - Choosing between
@State,@Binding,@Bindable,@Environment, plain property - Debugging with
Self._printChanges(); concurrency warnings in view code
Identity: the root concept
SwiftUI sees three things: identity, lifetime, dependencies. Views with the same identity are "different states of the same conceptual UI element"; distinct identities are distinct views.
Structural identity = type + position in the hierarchy. An
if/elsecreates two identities (_ConditionalContent) — flipping the branch destroys/recreates the view: state resets, transitions crossfade instead of animating.Explicit identity =
id:in ForEach or.id(_:)(also the target forScrollViewReader.scrollTo). Changing an explicit id is a new identity — new lifetime, fresh state. (That's the.id(item.id)force-refresh trick — use it knowingly.)The inert-modifier rule (the most under-used fix): prefer one view whose modifiers vary over branching —
// ❌ two identities; state resets, transition crossfades if expired { content.opacity(0.3) } else { content } // ✅ one identity; cheap, pruned when inert content.opacity(expired ? 0.3 : 1.0)Inert values (opacity 1, padding 0) cost nothing. "By default, try to preserve identity."
Conditionally include a view inside a stack rather than conditionally wrapping the stack.
Lifetime: state is tied to identity
- View values are ephemeral — created for comparison, then destroyed. Never rely on the struct instance; identity provides continuity.
- "Whenever the identity changes, the state is replaced" —
@State/@StateObjectstorage tears down and reinitializes. If state "randomly resets," find the identity change. - WWDC26:
@Stateis a macro with lazy initialization of@Observableclasses (backported to iOS 17) — the stored object initializes once per lifetime, not on every view-value init. Remove default values when also assigning ininit(source-breaking edge).
ForEach identifier rules (the flashing-list checklist)
- Stable — never
var id = UUID()computed per access (everything flashes/reanimates). - Not indices — insert-at-front reads as insert-at-end; rows animate wrongly.
- Unique — duplicate IDs drop rows.
- Use persistent/database-derived IDs; that's what
Identifiableis for. Range ForEach (0..<n) only with a constant range. - Constant views per element: an
iffilter inside ForEach (0-or-1 views) orAnyViewforces List to resolve every row just to count them. Filter in the data, and cache the filtered collection in the model — an inline.filterre-runs linearly on every body. - List/Table gather all identifiers eagerly — cheap IDs = fast loads.
Dependencies: the graph, not the tree
- Every piece of data read in body is a dependency; only views whose dependency changed re-run, and value comparison prunes unchanged subtrees. Stable identity is "the backbone of the dependency graph."
- Scope dependencies tightly: pass the subview what it renders (the
Image, not the whole model). Extracting subviews is free — "breaking up one view into multiple doesn't hurt performance" — and shrinks invalidation scope. - Observation (
@Observable) tracks per property, per instance — a view re-renders only when a property it actually read changes, including through computed properties, arrays, optionals, and nesting. - Migration from
ObservableObject: drop conformance +@Published→@Observable;@ObservedObject→ delete or@Bindable;@EnvironmentObject→@Environment. Invalidation narrows from whole-object to read-properties — a free performance win.
State ownership: the decision rules
Ask Apple's three questions: what data does the view need · how does it manipulate it · where does truth live?
| Situation | Use |
|---|---|
| Display-only, parent owns it | plain let property |
| Transient, view-local UI state | @State (group related fields into one struct with mutating methods) |
| Write access to someone else's truth | @Binding (bindings compose: $config.note) |
| Observable model owned by this view | @State (lazy-init since WWDC26 macro) |
Observable model, needs $model.field bindings only |
@Bindable |
| Observable model, globally available | @Environment |
| Observable model, none of the above | p |
Установить data-flow в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditGlobGrepFAQ
Что делает скилл data-flow?
SwiftUI's actual mental model — view identity, lifetime, and dependencies (the Demystify canon), state ownership decision rules, Observation's per-property tracking, body-performance discipline, and the main-actor concurrency contract. Use when state resets mysteriously, views re-render too often, animations glitch between branches, choosing @State vs @Bindable vs plain property, or debugging "why did body run."
Как установить скилл data-flow?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл data-flow запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic