//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)
}
Asked
Active
Viewed 170 times
0

Rengers
- 14,911
- 1
- 36
- 54

user2389743
- 11
- 6
-
Do you expect an array as a return value? – ielyamani May 17 '19 at 11:45
-
yes array of index 0 , index 1 and so on..... – user2389743 May 18 '19 at 05:13
1 Answers
0
Don't use Objective-C stuff like NSPredicate
and NSArray
when you don't have to. Use Swift's filter
and map
.
From what you described in the comments, you want to keep only the inner arrays that contains the searched text. You can do this:
filterArr = actors.filter { $0.contains(searchController.searchBar.text!) }
If you want to keep only the inner arrays that contains items that contains the search text, do this:
filterArr = actors.filter { $0.contains { $0.contains(searchController.searchBar.text!) } }

Sweeper
- 213,210
- 22
- 193
- 313
-
This is working fine but if i search for 'a0' only a0 value is available in the array and same is displaying in the cell. – user2389743 May 18 '19 at 05:41
-
This is working fine but if i search for 'a0' only a0 value is available in the array and same is displaying in the cell. actually my table view cell contains ->["a0","b0","c0","d0"] in one cell and this array data ->["a1","b1","c1","d1"] is in another cell.. Here what am trying to do is if i search for 'a0' i want all the values of "a0","b0","c0","d0" and similarly if i search for 'c0' i want all the values -> "a0","b0","c0","d0". and few arrays has info like ->[[a0","b0","c0","d0],[a1","b1","c0","d0]]i don't know whether is it possible or not. if it is possible please help me. thank you – user2389743 May 18 '19 at 05:48