title: SwiftUI - Group NSFetchRequest by date to display in list with sections
body: <p>I'm building a SwiftUI app where it shows a list of values containing their associated date and duration. At the moment the <code>ContentView</code> is just listing all the values (date ascending). </p>
  
  <p>What I would like to achieve is so that entities are grouped by date and into their relevant sections, for example:</p>
  
  <p><strong>Current</strong></p>
  
  <ul>
  <li>Section: "date"
  
  <ul>
  <li>Duration: 50, Date: 1st Jan</li>
  <li>Duration: 48, Date: 1st Jan</li>
  <li>Duration: 21, Date: 2nd Jan</li>
  <li>Duration: 57, Date: 3rd Jan</li>
  </ul></li>
  </ul>
  
  <p><strong>Aim</strong></p>
  
  <ul>
  <li>Section: "1st Jan"
  
  <ul>
  <li>Duration: 50, Date: 1st Jan</li>
  <li>Duration: 48, Date: 1st Jan</li>
  </ul></li>
  <li>Section: "2nd Jan"
  
  <ul>
  <li>Duration: 21, Date: 2nd Jan</li>
  </ul></li>
  <li>Section: "3rd Jan"
  
  <ul>
  <li>Duration: 57, Date: 3rd Jan</li>
  </ul></li>
  </ul>
  
  <p>Any help is greatly appreciated, many thanks.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>// MARK: - ContentView
  
  struct ContentView: View {
  
      // MARK: - Variables
  
      @Environment(\.managedObjectContext) var managedObjectContext
      @FetchRequest(fetchRequest: EntityCore.fetch()) var entities
  
      // MARK: - Body
  
      var body: some View {
  
          NavigationView {
              List {
                  Section(header: Text("Date")) {
                      ForEach(entities) { (entity) in
                          EntityView(entity: entity)
  
                      }
                  }
  
              }.listStyle(GroupedListStyle())
               .navigationBarTitle(Text("Entities"))
  
          }
      }
  }
  
  // MARK: - PlankCore
  
  public class EntityCore: NSManagedObject, Identifiable {
  
      // MARK: - Variables
  
      @NSManaged public var duration: Int64
      @NSManaged public var date: Date?
  
      // MARK: - Fetch
  
      static func fetch() -&gt; NSFetchRequest&lt;EntityCore&gt; {
  
          let request = EntityCore.fetchRequest() as! NSFetchRequest&lt;EntityCore&gt;
          request.sortDescriptors = [NSSortDescriptor(key: "date", ascending: true)]
  
          return request
  
      }
  }
  </code></pre>