title: Filtering Array and displaying in Table View?
body: <p>I want to search an dictionary of exercises for the name key and then show the filtered result in the table view. I am using this function </p>
  
  <pre><code>func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
      let filtered = exercises.filter { $0["name"] == searchText }
      print(filtered)
  
      if(filtered.count == 0){
          searchActive = false;
      } else {
          searchActive = true;
      }
      self.exercisesTableView.reloadData()
  }
  </code></pre>
  
  <p>Variables:</p>
  
  <pre><code>var exercises = [Exercise]()
  var filtered: [NSMutableArray] = []
  var searchActive: Bool = false
  </code></pre>
  
  <p>In the search function I get the error</p>
  
  <blockquote>
    <p>Type'Exercise' has no subscript members</p>
  </blockquote>
  
  <p>and then i have the issue that the result is an NSMutableArray and so I cant set the result names as cell text to display</p>
  
  <blockquote>
    <p>Cannot convert value of type 'NSMutableArray' to type 'String' in coercion</p>
  </blockquote>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
      if (searchActive){
          cell.textLabel?.text = filtered[indexPath.row] as String
      } else {
          let exercise = exercises[indexPath.row]
  
          cell.textLabel!.text = exercise.name
      }
      return cell
  }
  </code></pre>
  
  <p>Here is my Exercise dictionary for reference:</p>
  
  <pre><code>final public class Exercise {
      var id: Int
      var descrip: String
      var name: String
      var muscles: [Int]
      var equipment: [Int]
  
      public init?(dictionary: [String: Any]) {
  
          guard
              let id = dictionary["id"] as? Int,
              let descrip = dictionary["description"] as? String,
              let name = dictionary["name"] as? String,
              let muscles = dictionary["muscles"] as? [Int],
              let equipment = dictionary["equipment"] as? [Int]
  
              else { return nil }
  
          self.id = id
          self.descrip = descrip
          self.name = name
          self.muscles = muscles
          self.equipment = equipment
  
      }
  </code></pre>
  
  <p>I can fix the second error by making var filtered: [String] = [] so it can be used as a cell title, but that doesnt resolve the first error and im not sure is the right way to go about it?</p>