I have data stored in this fashion,
var data = [(String, Array<String>)]()
Example Data:
[(A, [Apple, Andy, Android]), (B, [Banana, Breakfast])]
I am trying to apply a search filter on this data by using Predicate,
Here is what I am tried and failed,
func updateSearchResultsForSearchController(searchController: UISearchController) {
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text)
let array = (data as NSArray).filteredArrayUsingPredicate(searchPredicate)
data = array as! [(String, Array<String>)]
//reload tableView with fresh data
self.tableView.reloadData()
}
Its failing as I am trying to convert my data into NSArray to apply filter and then trying to convert the filtered array back to my desired format. (I know that this conversion won't work, this is just to give you guys an idea of what I am trying to do.)
My question is how to apply search filter on my data's array of Strings ?
As in, if the search term is "an", the data should filter to
[(A, [Andy, Android]), (B, [Banana])]
databut not on the second param, which is my String array. I think we are close, can you explain me the code please? - Nagendra Rao