I have two arrays of data that I would like to search through and don't know how to search both with a UISearchController
struct Fish {
var name: String
var price: Int
}
var fishArray: [Fish] = [ Fish(name: "Bass", price: 1),
Fish(name: "Pike", price: 2),
Fish(name: "Carp", price: 3),
Fish(name: "Bluegill", price: 4),
Fish(name: "Catfish", price: 5)]
struct Weapons {
var name: String
var price: Int
}
var weaponsArray: [Weapons] = [ Weapons(name: "Sword", price: 1),
Weapons(name: "Knife", price: 2),
Weapons(name: "Gun", price: 3),
Weapons(name: "Poison", price: 4),
Weapons(name: "Hammer", price: 5)]
The searching happens here. And it works great to search through just the Weapons but how can I add in the Fish and multiple other arrays later.
func filterContentForSearchText(_ searchText: String, scope: String = "All") {
filteredData = weaponsArray.filter({( weapon : Weapons) -> Bool in
return weapon.name.lowercased().contains(searchText.lowercased())
})
mainTableView.reloadData()
}
Hope this makes sense to someone! Thanks!