How can I filter an array of dictionaries in 'updateSearchResultsForSearchController' to search a UITableView with Swift
<p>I've been going round in circles trying to implement search functionality in my UITableView.</p>

<p>I've followed loads of instructions here on stackoverflow and watched a ton of videos on YouTube and I feel like I know how to implement UISearchController now but i'm struggling how to actually filter my array in the <code>updateSearchResultsForSearchController</code> function.</p>

<p>I've managed to get search working if I have a simple array of string values as you see in most of the online examples for implementing search but I have an array of dictionaries and have no idea how to use <code>.filter</code> to get at the key/value pairs in the dictionary.</p>

<p>My peopleData array is an array of dictionaries that comes from a JSON file which looks like this:</p>

<pre><code>{
  "people": [
  {
    "ID" : "1",
    "firstname" : "Bob",
    "lastname" : "Smith",
    "age" : 25,
    "gender" : "Male"
  },
  {
    "ID" : "2",
    "firstname" : "Fred",
    "lastname" : "Smith",
    "age" : "52",
    "gender" : "Male"
  }
           ]
}  
</code></pre>

<p><br></p>

<p>My view controller looks like this:</p>

<pre><code>//  Created by Elliot Wainwright on 26/02/2016.  
//  Copyright © 2016 Elliot Wainwright. All rights reserved.

import UIKit

class SelectPersonTableViewController: UITableViewController {

    var myList:NSMutableArray = []
    var personData:NSMutableArray = []
    var filteredPeopleData:NSMutableArray = []

    var searchController : UISearchController!
    var resultsController = UITableViewController()

    @IBOutlet var selectPersonTable: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        guard let path = NSBundle.mainBundle().pathForResource("PeopleData", ofType: "json") else {
            print("error finding file")
            return
        }

        do {
            let data: NSData? = NSData(contentsOfFile: path)
            if let jsonResult: NSDictionary =
                try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary {
                    personData = jsonResult["people"] as! NSMutableArray
                }
            } catch let error as NSError {
                print("Error:\n \(error)")
                return
            }

        self.resultsController.tableView.dataSource = self
        self.resultsController.tableView.delegate = self

        self.searchController = UISearchController(searchResultsController: self.resultsController)
        self.tableView.tableHeaderView = self.searchController.searchBar
        self.searchController.searchResultsUpdater = self
        definesPresentationContext = true

        selectPersonTable.reloadData()
    }

    func updateSearchResultsForSearchController(searchController: UISearchController) {
        //Filter through the array

            //---------------------------------------------
            //I have no idea how to do this for my array!!!
            //---------------------------------------------

        //Update the results TableView
        self.resultsController.tableView.reloadData()
    }
    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
        return 1
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
        if tableView == self.tableView {
            return self.peopleData.count
        } else {
            return self.filteredPeopleData.count
        }
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)

        if tableView == self.tableView {
            for person in personData {
                let thisPerson = personData.objectAtIndex(indexPath.row)
                cell.textLabel?.text = thisPerson["person"] as? String
            }
        } else {
            for person in filteredPeopleData {
                let thisPerson = filteredPeopleData.objectAtIndex(indexPath.row)
                cell.textLabel?.text = thisPerson["person"] as? String
            }
        }

        return cell
    }

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        myList.addObject(personData.objectAtIndex(indexPath.row))
        navigationController?.popViewControllerAnimated(true)
    }

    // MARK: - Navigation

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        var vc = segue.destinationViewController as! ViewController
        vc.peopleList = myList
    }
}
</code></pre>

<p><br></p>

<p>As you can see, In <code>ViewDidLoad</code> I get the content of the JSON file within 'people' <code>personData = jsonResult["people"] as! NSMutableArray</code> so I end up with an array of dictionaries.</p>

<p>Ideally, users would be able to type something in the UISearchBar and the array (and so the table) would be filtered to show any elements that contain any values that include part of what the user has typed. So typing "ith" would return both rows as 'ith' appears in 'Smith' for both elements in the array.</p>

<p>At very least, i'd like to be able to search on at least one key/value.</p>