NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Is it legal to use a NavigationStack inside a NavigationStack?

Forums > SwiftUI

So, as per the title, I have experimented and been able to use the above situation.

I can manage a NavigationStack with its own path nested within another NavigationStack, with even it's own path.

Now, if I wanted to achieve a certain separation of concerns, would it be acceptable to nest them in such a fashion, where you have at least one (even multiple) NavigationStacks living within a root NavigationStack?

I do see that I could use a single root NavigationStack at the top of my view hierarchy, and keep passing a reference binding to the path variable to my child views on and on and on.. but this gets frustrating to manage after a time.

So, maybe I've misunderstood the WWDC videos or key Apple documentation - but is nesting these NavigationStacks as a child of a root stack an acceptable practice? Or, am I treading in deep waters?



Did you come to a conclusion about this by chance?


Hacking with Swift is sponsored by Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.