<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Oliver Gilcher on Medium]]></title>
        <description><![CDATA[Stories by Oliver Gilcher on Medium]]></description>
        <link>https://medium.com/@olivergilcher?source=rss-3662e154bbfd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Y3Hz3TuzMTel5-cr.</url>
            <title>Stories by Oliver Gilcher on Medium</title>
            <link>https://medium.com/@olivergilcher?source=rss-3662e154bbfd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:54:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@olivergilcher/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Managing Deep Navigation in SwiftUI with a Coordinator Architecture]]></title>
            <link>https://medium.com/@olivergilcher/managing-deep-navigation-in-swiftui-with-a-coordinator-architecture-8bba3fc23ceb?source=rss-3662e154bbfd------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bba3fc23ceb</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Oliver Gilcher]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 05:33:05 GMT</pubDate>
            <atom:updated>2026-03-16T05:33:05.667Z</atom:updated>
            <content:encoded><![CDATA[<h4>A scalable approach to managing NavigationStack flows in real-world SwiftUI applications</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0d9U5KlpLKIXaHYKP_RFKw.png" /><figcaption>navigation architecture diagram</figcaption></figure><p>SwiftUI’s <strong>NavigationStack</strong> works well for simple navigation flows.</p><p>But as applications grow and navigation becomes deeper and more interconnected, managing navigation state quickly becomes difficult.</p><p>Navigation logic often ends up scattered across many views, deep navigation stacks become harder to reason about, and coordinating transitions between features becomes fragile.</p><p>These problems become especially noticeable once navigation flows reach several layers deep.</p><p>In this article, we’ll walk through a simple coordinator-based architecture that centralizes navigation state while keeping SwiftUI views lightweight and focused purely on UI.</p><p>The full working demo project is available on GitHub:</p><p><a href="https://github.com/ogilcher/swiftui-navigation-coordinator">https://github.com/ogilcher/swiftui-navigation-coordinator</a></p><h3><strong>The Problem with View-Driven Navigation 😒</strong></h3><p>In many SwiftUI apps, navigation is triggered directly inside views:</p><pre>NavigationLink(destination: PetDetails(pet: pet)) {<br>    Text(pet.name)<br>}</pre><p>This works well at first, but as applications grow it introduces several issues:</p><ul><li>Views become responsible for routing decisions</li><li>Navigation logic spreads throughout the view hierarchy</li><li>Reusing flows becomes harder</li><li>Debugging navigation state becomes difficult</li></ul><p>Once navigation flows become deeper, this pattern becomes harder to manage.</p><p>For example:</p><pre>Home<br>  → Pets Dashboard<br>  → Pet Details<br>  → Edit Pet</pre><p>In larger apps, you may also need to jump between feature domains:</p><pre>Home<br>  → Settings<br>  → Security</pre><p>At this point, navigation state is no longer trivial.</p><h3><strong>Introducing a Coordinator 🎉</strong></h3><p>A coordinator centralizes navigation state and routing decisions.</p><pre>import SwiftUI<br><br>@Observable<br>@MainActor<br>final class AppCoordinator {<br>    var path: [AppScreen] = []<br><br>    func push(_ screen: AppScreen) {<br>        path.append(screen)<br>    }<br>}</pre><p>Instead of views controlling navigation directly, views simply <strong>request navigation actions.</strong></p><p>For example:</p><pre>coordinator.push(.pet(.details(pet.id)))</pre><p>The coordinator then updates the navigation state for the entire application.</p><p>This creates a clean separation of responsibilities:</p><p>Views — Render UI and request navigation</p><p>Coordinator — Manages navigation state</p><p>Router — Converts routes into SwiftUI views</p><h3><strong>Architecture Overview</strong></h3><p>The demo project is build around three primary components:</p><p>Content View → AppCoordinator → Navigation Router → SwiftUI Screens</p><ul><li>ContentView owns the coordinator and sets up the navigation stack</li><li>AppCoordinator manages navigation state</li><li>NavigationRouter resolves routes into views</li><li>Screens render UI and request navigation actions from the coordinator</li></ul><p>This keeps navigation logic centralized while keeping views simple.</p><h3><strong>Defining Routes 📝</strong></h3><p>Navigation routes are defined using a single canonical type:</p><pre>enum AppScreen {<br>    case core(CorePath)<br>    case settings(SettingsPath)<br>    case pet(PetPath)<br>}</pre><p>Each feature defines its own route set.</p><p>Example:</p><pre>enum PetPath {<br>    case dashboard<br>    case details(UUID)<br>    case edit(UUID)<br>}</pre><p>This approach makes navigation type-safe and explicit.</p><h3><strong>Routing Views 🛜</strong></h3><p>A router converts navigation routes into concrete views:</p><pre>// ContentView.swift<br><br>struct ContentView: View {<br>    @State private var coordinator = AppCoordinator()<br><br>    var body: some View {<br>        NavigationStack(path: $coordinator.path) {<br>          NavigationRouter.build(for: screen, coordinator: coordinator)<br>              .navigationDestination(for: AppScreen.self) { screen in <br>                NavigationRouter.build(for: screen, coordinator: coordinator)<br>              }<br>        }<br>        .environment(coordinator)<br>    }<br>}</pre><p>This ensures that:</p><ul><li>navigation state stays centralized</li><li>view construction stays separate from routing logic</li></ul><p><strong>Example Navigation Flow</strong></p><p>The demo project includes a small pet management feature to demonstrate navigation.</p><p>Example flow:</p><pre>Home<br>  → Pets Dashboard<br>  → Pet Details<br>  → Edit Pet</pre><p>Each transition is handled through the coordinator.</p><p>For example:</p><pre>coordinator.push(.pet(.edit(pet.id)))</pre><p>This updates the navigation stack managed by the coordinator.</p><h3><strong>Benefits of This Approach ✅</strong></h3><p>Using a coordinator provides several advantages:</p><ul><li>Centralized navigation state</li><li>Type-safe routing</li><li>Cleaner SwiftUI views</li><li>Easier debugging of navigation flows</li><li>More scalable architecture as apps grow</li></ul><p>SwiftUI remains responsible for rendering UI, while navigation logic stays contained within a single place.</p><h3><strong>Conclusion</strong></h3><p>SwiftUI’s navigation APIs are powerful, but as applications grow, introducing structure around navigation becomes increasingly valuable.</p><p>A coordinator-based architecture allows you to:</p><ul><li>centralize navigation logic</li><li>simplify complex flows</li><li>keep views focused on UI</li></ul><p>If you’d like to explore the full working example, you can find the demo project here:</p><p><a href="https://github.com/ogilcher/swiftui-navigation-coordinator">https://github.com/ogilcher/swiftui-navigation-coordinator</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bba3fc23ceb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>