Grouped queries in SwiftUI

Querying While developing Maby I needed to retrieve all events that happened, grouped by dates. Now of course I could just slap a FetchRequest and then manually group the results into a dictionary, specially given how easy it is with the grouping init, but it turns out that there’s a better way. Since iOS/iPadOS/tvOS 15, macOS 12 and watchOS 8 there’s a new fetch request in town called SectionedFetchRequest that allows us to specify a type to group by and an entity to group, so for example in my case I could just do the following:

Unrecognized selector objectAtIndex

Unrecognized selector objectAtIndex 2022-06-21 22:41:30.447763+0200 App[56115:1179524] -[__NSCFSet objectAtIndex:]: unrecognized selector sent to instance 0x600003df9c20 This happened with the following code, basically when trying to do a ForEach on a property coming from a CoreData model: import CoreData import SwiftUI struct BudgetView: View { @FetchRequest(entity: CategoryGroup.entity(), sortDescriptors: []) var categoryGroups: FetchedResults<CategoryGroup> var body: some View { VStack { List { ForEach(categoryGroups, id: .id) { group in Text( ForEach(group.categories, id: .id) { category in Text(category.