swift 3 filter array of dictionaries by string value of key in dictionary
<p>I have a class such as this</p>

<pre><code>class FoundItem : NSObject {

var id : String!
var itemName : String!
var itemId : Int!
var foundBy : String!
var timeFound : String!

init(id: String,
    itemName: String,
    itemId: Int,
    foundBy: String,
    timeFound: String)

{
    self.id = id
    self.itemName = itemName
    self.itemId = itemId
    self.foundBy = foundBy
    self.timeFound = timeFound

}
</code></pre>

<p>and I reference it on my </p>

<pre><code>class MapViewVC: UIViewController, MKMapViewDelegate {

var found = [FoundItem]()

var filterItemName : String()

}
</code></pre>

<p>My <code>FoundItem</code> are generated by into an array of dictionaries from my class of <code>FoundItem</code> from a firebase query. I then get a string of that <code>itemName</code> that is generated from an another view controller that is a collection view on the <code>didSelection</code> function. I want to take that string and then filter or search the arrays with the string <code>itemName</code> that is equal from the <code>itemName</code> string from my previous <code>viewController</code>. Then removed the array of dictionaries that are not equal to the <code>itemName</code>. Not just the objects, but the entire array that contains non-equal key, value pair. I have looked for days, and I am stuck on filtering an array of dictionaries created from a class. I have looked and tried NSPredicates, for-in loops, but all that ends up happening is creating a new array or bool that finds my values or keys are equal. Here is the current function I have written. </p>

<pre><code>func filterArrayBySearch() {

    if self.filterItemName != nil {

        dump(found)

        let namePredicate = NSPredicate(format: "itemName like %@", "\(filterItemName)")
        let nameFilter = found.filter { namePredicate.evaluate(with: $0) }

        var crossRefNames = [String: [FoundItem]]()
        for nameItemArr in found {
            let listName = nameItem.itemName
            let key = listName

            if crossRefNames.index(forKey: key!) != nil {

                crossRefNames[key!]?.append(nameItemArr)

                if !("\(key)" == "\(filterItemName!)") {

                    print("------------- Success have found [[[[[[    \(key!)    ]]]]]] and \(filterItemName!) to be equal!!")

                     // crossRefNames[key!]?.append(nameItemArr)

                } else {

                    print("!! Could not find if \(key!) and \(filterItemName!) are equal !!")
                }


            } else {

                crossRefNames[key!] = [nameItemArr]
            }
        }

    } else {

        print("No Data from Search/FilterVC Controller")
    }
}
</code></pre>

<p>Can anyone help? It seems like it would be the simple task to find the value and then filter out the dictionaries that are not equal to the <code>itemName</code> string, but I keep hitting a wall. And running into for-in loops myself :P trying different things to achieve the same task. </p>