title: How to properly group a list fetched from CoreData by date?
body: <p>For the sake of simplicity lets assume I want to create a simple todo app. I have an entity Todo in my xcdatamodeld with the properties <code>id</code>, <code>title</code> and <code>date</code>, and the following swiftui view (example pictured):</p>
  
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct ContentView: View {
  
    @Environment(\.managedObjectContext) var moc
    @State private var date = Date()
    @FetchRequest(
      entity: Todo.entity(),
      sortDescriptors: [
        NSSortDescriptor(keyPath: \Todo.date, ascending: true)
      ]
    ) var todos: FetchedResults&lt;Todo&gt;
  
    var dateFormatter: DateFormatter {
      let formatter = DateFormatter()
      formatter.dateStyle = .short
      return formatter
    }
  
    var body: some View {
      VStack {
        List {
          ForEach(todos, id: \.self) { todo in
            HStack {
              Text(todo.title ?? "")
              Text("\(todo.date ?? Date(), formatter: self.dateFormatter)")
            }
          }
        }
        Form {
          DatePicker(selection: $date, in: ...Date(), displayedComponents: .date) {
            Text("Datum")
          }
        }
        Button(action: {
          let newTodo = Todo(context: self.moc)
          newTodo.title = String(Int.random(in: 0 ..&lt; 100))
          newTodo.date = self.date
          newTodo.id = UUID()
          try? self.moc.save()
        }, label: {
          Text("Add new todo")
        })
      }
    }
  }
  </code></pre>
  
  <p>The todos are sorted by date upon fetching, and are displayed in a list like this: </p>
  
  <p><a href="https://i.stack.imgur.com/hB3zZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hB3zZ.png" alt="What I got"></a></p>
  
  <p>I want to group the list based on each todos respective date as such (mockup):</p>
  
  <p><a href="https://i.stack.imgur.com/5WrRR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5WrRR.png" alt="What I want"></a></p>
  
  <p>From my understanding this could work with Dictionaries in the <code>init()</code> function, however I couldn't come up with anything remotely useful. Is there an efficient way to group data?</p>