Goal: To create a Dynamic TabView that displays Todo Items filtered by their Category on each TabView. What is the best way to go about this in my current code? I don't want to modify the FetchRequest.
This is the TabView, I want to show the List of my Todos filtered on each Tab.
TabBarView(currentTab: $currentTab, tabBarOptions: categoryTitles)
TabView(selection: $currentTab) {
Text("List of todo items filtered by the Category Title").tag(0)
Text("tab2").tag(1)
}
.tabViewStyle(.page(indexDisplayMode: .never))
This is what my Todo Items currently look like unfiltered
List {
ForEach(sections) { section in
Section(header: Text(section.id.capitalized)) {
ForEach(section) { todo in
TodoRowView(todo: todo)
.frame(maxWidth: .infinity)
.listRowSeparator(.hidden)
}
.onDelete { indexSet in
deleteTodo(section: Array(section), offsets: indexSet)
}
}
}
}
struct TabBarView: View {
@Binding var currentTab : Int
var tabBarOptions: [String] = ["Test1", "Test2", "Test3"]
var body: some View {
ScrollView(.horizontal) {
HStack(spacing: 20 ) {
ForEach(Array(zip(self.tabBarOptions.indices, self.tabBarOptions)),
id: \.0,
content: {
index, name in
TabBarItem(tabBarItemName: name, tab: index, currentTab: self.$currentTab)
})
}
}
}
}
@FetchRequest(entity: Category.entity(), sortDescriptors: []) var categories: FetchedResults<Category>