- I currently create a corresponding view conforming to
UIViewControllerRepresentable
for each of the UIViewControllers and present them like so - Thinking of setting up a view protocol and make the views I wish to present conform to that and just set the properties there and
- Iterate through an enum of the aforementioned views
What’s a better way to structure this?
struct MyRoutesSectionViewObject: Hashable {
var title: String
var iconString: String
var count: Int
var badgeIconString: String?
}
enum MyRoutesType: CaseIterable, Hashable {
case savedRoutes(MyRoutesSectionViewObject)
case plannedRoutes(MyRoutesSectionViewObject)
case recordedRoutes(MyRoutesSectionViewObject)
case offlineRoutes(MyRoutesSectionViewObject)
static var allCases: [MyRoutesType] {
return [.savedRoutes(MyRoutesSectionViewObject(title: "Saved",
iconString: "savedIcon",
count: 10)),
.plannedRoutes(MyRoutesSectionViewObject(title: "Planned",
iconString: "plannedIcon",
count: 10)),
.recordedRoutes(MyRoutesSectionViewObject(title: "Recorded",
iconString: "recordedIcon",
count: 10)),
.offlineRoutes( MyRoutesSectionViewObject(title: "Offline",
iconString: "offlineIcon",
count: 10,
badgeIconString: "premiumBadge"))]
}
}
struct MyRoutesSectionView: View {
var body: some View {
ForEach(MyRoutesType.allCases, id: \.self) { routeType in
switch routeType {
case .savedRoutes(let routeObject):
NavigationLink(destination: SavedRoutesView()) {
MyRoutesNavigationLinkView(myRoutesObject: routeObject)
}
case .plannedRoutes(let routeObject):
NavigationLink(destination: PlannedRoutesView()) {
MyRoutesNavigationLinkView(myRoutesObject: routeObject)
}
case .recordedRoutes(let routeObject):
NavigationLink(destination: RecordedRoutesView()) {
MyRoutesNavigationLinkView(myRoutesObject: routeObject)
}
case .offlineRoutes(let routeObject):
NavigationLink(destination: SavedRoutesView()) {
MyRoutesNavigationLinkView(myRoutesObject: routeObject)
}
}
}
}
}