title: How to filter a list of dates by year interactively in SwiftUI
body: <p>I have a NSManagedObject Subclass coming from a core data entity <code>MyEntity</code> with:</p>
  <pre><code>@NSManaged public var name: String
  @NSManaged public var date: Date
  </code></pre>
  <p>and a list. I prepared a ScrollView that holds Buttons (?) that could be used to filter the list</p>
  <pre><code>func groupYears(fetchedResults: FetchedResults&lt;MyEntity&gt;) -&gt; [Int] {
      var result = [Int]()
      for fetchedResult in fetchedResults {
          let component = Calendar.current.dateComponents([.year], from: fetchedResult.date)
          if !result.contains(component.year!) {
              result.append(component.year!)
          }
      }
      return result
  }
  </code></pre>
  <pre><code>@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \MyEntity.date, ascending: true)]) var fetchedResults: FetchedResults&lt;MyEntity&gt;
  </code></pre>
  <pre><code>VStack {
      ScrollView(.horizontal, showsIndicators: false) {
          HStack(spacing: 15) {
              Button(action: {}) { Text(&quot;all&quot;) }
              ForEach(groupYears(fetchedResults: fetchedResults), id: \.self) { year in
                  Button(action: {}) { Text(String(year)) }
              }
          }
      }
      List(fetchedResults, id: \.self) { result in
          VStack(alignment: .leading) {
              Text(result.name)
              Text(dateFormatter.string(from: result.date))
          }
      }
  }
  </code></pre>
  <p>I want to click a button and the list should dynamically filter the related year.</p>
  <p>How can I filter the list dynamically?</p>