Member-only story
Featured
Navigator and External Destinations
Obtaining and using external views in a modular application.
I’ve written at length about NavigationDestination types, also known as enumerated views. Fundamentally, a destination is a View. Ask an SwiftUI enumerated destination to display itself, and it will.
NavigationDestination’s can be pushed, presented, and manipulated as needed. Passed and returned as values. They’re extremely powerful architectural concepts on which Navigator and many other SwiftUI-based navigation systems are founded.
But they do suffer from one drawback.
Namely that they require the destination to provide the views needed as part of the protocol requirements. They are Views, after all, and views must have a view body.
And in many cases that’s not a problem.
public enum SharedDestinations: NavigationDestination {
case newOrder
case orderDetails(Order)
case produceDetails(Product)
public var body: some View {
switch self {
case .newOrder:
NewOrderView()
case .orderDetails(let order):
OrderDetailsView(order)
case .produceDetails(let product):
ProduceDetailsView(for: product)
}
}
}
