Is it possible to nest filters using scope bars?

I have a tableview with a search bar and scope bar beneath. When the user choses an option from the scope bar, I want to reload the tableview with the filtered items, change the scope bar, and then refilter given choices from the new scope bar. It is easy enough to do the first two parts,


func filterContentForSearchText(_ searchText: String, scope: String = "All") {

tfilteredPlants = trees.filter({( plant : Plant) -> Bool in

let doesTreeMatch = (scope == "All") || (plant.TreeShrub == scope)

if searchBarIsEmpty() {

return doesTreeMatch

} else {

return doesTreeMatch && plant.commonName.lowercased().contains(searchText.lowercased())

}

})

if scope == "Shrub" {

print("Shrub")

treeSearchController.searchBar.scopeButtonTitles = ["All Leaf Types", "Simple", "Compound"]

}

tableView.reloadData()

}


But now I want to match a different variable, call it Leaf, based on Compound or Simple being chosen, And I would like to filter again based on that. I could add a sequence of view controllers and segue between them, which would be messy but possible, but I was wondering whether there was a more compact approach.

I have not tested, but could you :

- add a param in the filterContentForSearchText signature

func filterContentForSearchText(_ searchText: String, scope: String = "All", secondaryScope: String = "All Leaf Types")


create a leafType property in Plant class (plant.leafType) to hold the value of secondary search


- test against this param if not empty

let doesTreeMatch = ((scope == "All") || (plant.TreeShrub == scope)) && (secondaryScope == "All Leaf Types" || plant.leafType == secondaryScope)


Note: TreeShrub should start with lowercase to conform to Swift conventions.

Is it possible to nest filters using scope bars?
 
 
Q