Goal: I want to to show a list of Todo
items by their due dates which I have already achieved. But I also wanna show a list of a different entity, Categories
on the same View above the list of Todo items. The categories are buttons to take you to a list of todo items filtered to that category. I set a relationship of Category to have many todos. How do I change my FetchRequest to support the added relationship?
Here is the current SectionedFetchRequest
below. If I try to add a new FetchRequest for Categories I get a crash.
@SectionedFetchRequest(entity: Todo.entity(),
sectionIdentifier: \.dueDateRelative,
sortDescriptors: [NSSortDescriptor(keyPath: \Todo.dueDate, ascending: true)],
predicate: nil,
animation: Animation.linear)
var sections: SectionedFetchResults<String, Todo>
ForEach(sections) { section in
Section(header: Text(section.id.description)) {
ForEach(section) { todo in
TodoRowView(todo: todo)
.frame(maxWidth: .infinity)
.listRowSeparator(.hidden)
}
.onDelete { indexSet in
deleteTodo(section: Array(section), offsets: indexSet)
}
}
}
// Causes Crash when added to existing Fetch Request
//@FetchRequest(entity: Category.entity(), sortDescriptors: []) var categories: FetchedResults<Category>