r/iOSProgramming • u/aviriha • 15m ago
Discussion Modular navigation using Scaffolding
Hey! I just released a new version of Scaffolding, a Swift package for modular navigation in SwiftUI. If you remember Stinsen, this has been made as it's spiritual successor.
It's been battle tested on few production applications already and been developer through each of their development phase as needs occured - but not to tend to specific needs of the app, but general purpose.
In terms of modularity support, each feature can expose a coordinator and keep its screens internal. The coordinator owns the navigation state, and views or their viewmodels call it when they need to go somewhere.
The reason for it to be made was a frustration with native SwiftUI navigation for large-scale applications or applications with complicated and reoccuring flows. TCA is whole ecosystem that's ever-changing, Stinsen has been dead for a while and most of the teams I worked with stayed on the UIKit coordinator pattern, which adds unnecessary boilerplate.
Modularizing the navigation doesn't work on any kind of magic - internally, the library works as a linked list which flattens, allowing for the navigation to become a tree rather than a simple stack.
The package supports push navigation, sheets, tabs, and split views. Here’s a small settings flow:
import Scaffolding
import SwiftUI
final class SettingsCoordinator: FlowCoordinatable {
var stack = FlowStack<SettingsCoordinator>(root: .settings)
func settings() -> some View {
SettingsView()
}
func account() -> some View {
AccountView()
}
}Inside SettingsView, a button can read the coordinator from the environment and push the account screen:
`@`Environment(SettingsCoordinator.self) private var settings
var body: some View {
Button("Account") {
settings.route(to: .account)
}
}The main addition in this release is typed child routes. If the parent flow declares \@`Route func settings() -> SettingsCoordinator { .init() }`, it can deep-link straight to the account screen:
route(to: .settings)?.route(to: .account)The first call returns SettingsCoordinator?, so Xcode can suggest the next route. The parent never needs access to AccountView, and both flows share a navigation stack so the user can swipe back across the feature boundary.
Thanks for reading! If you have any suggestions or questions, I'd gladly appreciate and answer them.
Let me know how you handle navigation in large-scale, modular applications.
Library: https://github.com/dotaeva/scaffolding
Documentation: https://dotaeva.github.io/scaffolding/documentation/scaffolding/


