A Pure SwiftUI NavigationPath to pop to any View.

Tuan Ho Si
3 min readJul 21, 2024

SwiftUI is continuously improving, and with SwiftUI supporting iOS 16.0 and later, it offers NavigationPath which makes it easier for us to manage navigation and pop or push views.

Although it has addressed some limitations of older versions, there are still some issues with popping back to a specific view and identifying the items currently inside the NavigationStack .

I have extended it in a way that is purely SwiftUI, using only what is available and writing it in the most basic way possible.

Now we can pop to any View in the NavigationStack based on the Codable objects we have appended to the NavigationPath.

Check out the demo video below and use it if it can help you in your project.

Demo Video

When debugging, I saw that we can completely view the items in NavigationPath, but I don’t understand why Apple doesn’t let us use it.
They only allow us to use these methods:

// The number of elements in this path.
public var count: Int { get }

/// A Boolean that indicates whether this path is empty.
public var isEmpty: Bool { get }

/// A value that describes the contents of this path in a serializable format.
public var codable: NavigationPath.CodableRepresentation? { get }

/// Appends a new codable value to the end of…

--

--

Tuan Ho Si
Tuan Ho Si

Written by Tuan Ho Si

iOS Developer. Think different. I am just a newbie in iOS Development, Machine Learning and Computer Vision. I just wanna share what I know as a newbie.

No responses yet