title: Adding a filter to an array in Swift 4
body: <p>I have a struct, which is my data model:</p>
  
  <pre><code>import Foundation
  
  struct Item : Codable {
  
  var cat:String
  var name:String
  var createdAt:Date
  // more 
  var itemIdentifier:UUID
  var completed:Bool
  
  func saveItem() {
      DataManager.save(self, with: itemIdentifier.uuidString)
  }
  
  func deleteItem() { DataManager.delete(itemIdentifier.uuidString)
  }
  
  mutating func markAsCompleted() {
      self.completed = true
      DataManager.save(self, with: itemIdentifier.uuidString)
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Then in my ViewController I have the following code to load the data, which goes into a TableView (sorted by the creation date).</p>
  
  <pre><code>func loadData() {
      items = [Item]()
      items = DataManager.loadAll(Item.self).sorted(by: {
          $0.createdAt &lt; $1.createdAt })
      tableView.reloadData()
  }
  </code></pre>
  
  <p>Now I would like to add a filter, so that only category goes into the TableView. For instance, only where cat equals "garden".</p>
  
  <p>How can I add that?</p>