I’m currently trying to allow users to set a custom order of views in a TabView
. Here is simplified code of how this is implemented (inside the TabView)
let viewOrder: [String] = ["View1", "View2", "View3", "View4"]
for viewIdentifier in viewOrder {
switch viewIdentifier {
case "View1":
View1()
case "View2":
View2()
case "View3":
View3()
case "View4":
View4()
default:
break
}
}
This isn’t a great/scalable way to approach this, and I want to add extra features. My idea was to create an struct which would hold the name of the view along with the view itself and some extra details:
struct MyView: Identifiable {
let id: UUID
let name: String
let mainView: any View
let otherParam: Bool
init(name: String, mainView: any View, otherParam: Bool) {
self.id = UUID()
self.name = name
self.mainView = mainView
self.otherParam = otherParam
}
}
However, this doesn’t seem work, or at least I can’t figure out how to successfully pass a view to and call it from the struct, especially if the view takes parameters.
How should this be approached instead, or what other resources should I look at?