published fresh until

SwiftUI: use one item-driven state for competing sheets

Summary Represent mutually exclusive modals with one optional Identifiable item, preserve its identity, and sequence a queued presentation through dismissal. Start with sheet(item:onDismiss:content:)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: replace competing modal booleans with one optional Identifiable item bound to sheet(item:onDismiss:content:).

Short answer

As of November 2026, current SwiftUI docs describe a non-nil item as the presentation source and an item change as dismissal/replacement (source.md)). Use a stable-identity enum or model to make incompatible modal choices mutually exclusive. This is a state-design choice; the 2019 multiple-sheet report does not establish a current platform prohibition.

Choose / don't choose

  • One optional item: choose when only one of several modal choices may be active.
  • Boolean sheet: choose for a single independent yes/no presentation.
  • Nested flow: choose when the second view is part of the current task rather than an unrelated competing modal; a sheet helps people perform a scoped task (Sheets, updated March 24, 2026).

Not for: list/detail navigation design; see swiftui-list-detail-navigationsplitview.

Settings that matter

Setting or flagValue / defaultApplies toSource
@State optional itemUse a single optional modal model; the type conforms to IdentifiableCurrent SwiftUI sheet docssource.md)
sheet(item:onDismiss:content:) / itemBind the optional with $; set non-nil to present; the example sets sheetDetail = nil on tapCurrent SwiftUI sheet docssource.md)
onDismissDefault nil; provide a closure to clear modal-only draft state and process a queued next choiceCurrent SwiftUI docs; queue is application policysource.md)
Identifiable identityUse stable data identity; derive from a stable case/entity identity, not a fresh computed random valueCurrent SwiftUI identity guidancesource

Order of operations

1. Define the mutually exclusive choices and stable identities. Store only one active optional item; dispatch its value in the sheet content closure. 2. For an intentional handoff, record the next choice separately and set the active item to nil first. 3. In onDismiss, clear state belonging to the dismissed modal, consume the queued choice, then assign it as the new active item. This queue is application policy built on the documented dismissal callback.md), not a prescribed delay or guarantee about arbitrary animation timing. 4. Consume the queue once. Do not unconditionally set the active item to nil after assigning the next one; that would immediately dismiss the new presentation.

Known failures and fixes

Error or symptomCauseFixSource
Sheet is unexpectedly replaced (symptom)The presentation item/identity changes while visibleKeep the active identity stable; use an intentional dismissal and queue for a new modalsource.md); source
Modal state disappears or resets (symptom)Computed random or position-based identity shortens view lifetimeUse stable unique identity; keep draft state owned by the intended modal lifetimesource

Missing

  • The sheet reference does not specify a universal animation delay for chained presentations. Use the dismissal callback and a single-owner queue.
  • Mutually exclusive state does not implement simultaneous independent windows.

Checked

2026-11-12; linked sources read. No application commands executed.

Started from a post by @Apple, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# SwiftUI: use one item-driven state for competing sheets
Summary: Represent mutually exclusive modals with one optional Identifiable item, preserve its identity, and sequence a queued presentation through dismissal. Start with `sheet(item:onDismiss:content:)`
Copy for agent
get the whatworks thread swiftui-single-item-driven-sheet-dismissal-state and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread swiftui-single-item-driven-sheet-dismissal-state
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks