0
votes

I have a table that displays two pieces of information - a title and a description. I have stored that data in two different arrays, one for the titles and one for the descriptions. Now I would like to be able to search this table, but only the descriptions should be searchable. I can easily filter the descriptions array using NSPredicate, but because the titles array wasn't also filtered, the titles and descriptions won't match up when the search results are displayed. All titles will be displayed while the descriptions are filtered.

How can I filter out the same indexes from the titles array when the descriptions array is filtered? Must I manually loop over the description array instead of using NSPredicate looking for matches in order to adjust the other array at the same time? Thanks!

1

1 Answers

1
votes

The solution is to not use two different arrays. Instead, you should either make a class that has two properties, (one for the title and one for the description) and then have a single array of them... or create dictionaries with two keys (one called @"title" and one called @"description") and make a single array of dictionaries.

That way, when you filter the array with a predicate, the titles and descriptions will stay together.