How to make SectionedFetchRequest return correct data?

Viewed 26

I am using SectionedFetchRequest to add section and data in a list view, but it always returns the incorrect grouping!

As you can see the list show incorrect data. The income sections shows expenses and expenses shows income

Here is my code:

struct CategoryExpenseView: View {
    
    @SectionedFetchRequest<Bool, MyTransaction> (
        sectionIdentifier: \.isExpense,
        sortDescriptors: [SortDescriptor(\.date, order: .forward)]
    ) private var tansactions: SectionedFetchResults<Bool, MyTransaction>
    
    var body: some View {
        NavigationView {
            List{
                ForEach(tansactions) { sections in
                    let title = sections.id ? "Expenses" : "Income"
                    Section(title) {
                        ForEach(sections) { data in
                            TransactionItemView(data)
                        }
                        
                    }
                }
                
            }.navigationTitle("Reports")
        }
    }
}

After reading documents and blogs, I couldn't figure out what's wrong! Any help is hight appriciated

enter image description here

0 Answers
Related