Although @Claude31 example works, I realized that there is a better way to tackle the problem.
As the tag only provides conformance to the bound var type, switching type of id from UUID to Self results in ForEach tagging the entries of Picker automatically. I don't need the redundant property, everyone is happy.
So, my solution is (cumbersomely written)
struct Tab: Identifiable, Hashable {
var id: Self { self }
var name: String
}
extension Tab {
var sampleData: [Tab] = ["Work", "Hobby", "Random"].map {Tab(name: $0)}
}
struct Test: View {
@State private var selectedTab: Tab = Tab.sampleData[0]
var body: some View {
VStack {
Picker("Tab", selection: $selectedTab) {
ForEach(Tab.sampleData) {tab in
Text(tab.name)
}
}
Text(selectedTab.name)
}
}
}
Unless there is some UUID superiority over Self as an identifier...