//Am not getting any search list of cells
//when am searching am getting empty array every time.
var actors = [["a0","b0","c0","d0"],["a1","b1","c1","d1"],["a2","b2","c2","d2"],["a3","b3","c3","d3"]]
var filterArr:[[String]] = []
func updateSearchResults(for searchController: UISearchController) {
print("Searching for text:----\(searchController.searchBar.text!)")
let predicate = NSPredicate(format: "SELF Contains[c] %@" , searchController.searchBar.text!)
filterArr = (actors as NSArray).filtered(using: predicate) as! [[String]]
print(filterArr)
}
答案 0 :(得分:0)
不必使用NSPredicate
和NSArray
之类的Objective-C东西。使用Swift的filter
和map
。
根据您在注释中描述的内容,您只想保留包含搜索文本的内部数组。您可以这样做:
filterArr = actors.filter { $0.contains(searchController.searchBar.text!) }
如果只想保留包含 搜索文本的项目的内部数组,请执行以下操作:
filterArr = actors.filter { $0.contains { $0.contains(searchController.searchBar.text!) } }