Multiple sheetisPresented doesn't work in SwiftUI
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In SwiftUI, attaching multiple .sheet(isPresented:) modifiers to the same view often leads to only one sheet showing reliably. The framework applies presentation modifiers in a specific order, and competing booleans can conflict. A better pattern is one sheet modifier driven by a single enum state.
Why Multiple Boolean Sheets Conflict
When two booleans become true around the same time, SwiftUI has to pick one presentation path. This can cause ignored actions or the wrong modal appearing.
This pattern is brittle as view complexity grows.
Use Enum Driven Sheet State
A single optional enum keeps intent explicit and scales well.
This avoids conflicting boolean state and keeps modal routing centralized.
Dismiss and Trigger Next Sheet Safely
If one sheet action should open another, dismiss first, then set the next state asynchronously on the next run loop turn.
This sequence prevents overlapping presentation calls.
Coordinate With Navigation and Alerts
SwiftUI views can also present alerts, confirmations, and navigation destinations. Centralizing modal state in a small coordinator object keeps interactions predictable.
Injecting this coordinator through environment object can simplify larger feature modules.
Preview and Test Modal Routing
As sheet logic grows, add focused previews and UI tests for each modal path. This catches regressions where a button updates state but no presentation appears because the host view changed unexpectedly.
For UI tests, tap each button and assert that expected text exists in the sheet content. Consistent test coverage helps prevent subtle routing breakage during refactors.
Common Pitfalls
A common mistake is stacking many boolean sheet flags and expecting deterministic behavior. Use one source of truth for modal presentation.
Another issue is trying to present a new sheet before the current one dismisses. Queue the next action after dismissal.
A third issue is placing .sheet deep in subviews that are conditionally created. If the host view disappears, presentation behavior becomes inconsistent.
Summary
- Multiple
.sheet(isPresented:)modifiers on one view can conflict. - Prefer one
.sheet(item:)with an enum based state model. - Dismiss current sheet before presenting another.
- Centralize modal routing for complex SwiftUI screens.
- Keep presentation modifier on a stable, always mounted view.
Related reading
- Multiple Type Constraints in Swift
- Multiple variable assignment in Swift
- MVC pattern on Android
- MVC pattern on Android
- My Android device does not appear in the list of adb devices
- My app was just rejected for using the Ad support framework. Which library is responsible?
- My prerelease app has been processing for over a week in iTunes Connect, what gives?
- Native iOS app What do I put in Facebook''s developer iPhone App Store ID under Settings, Basic?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.