1
votes

I have 3 core data entities.

MenuItems, Items, ItemLangs.

All entities has iItemId attribute. The user need to search using sItemName which can be found in the ItemLangs.

The UITableView contains array of MenuItems.

I have tried filteredArrayUsingPredicate but my predicate is not right. Do I need to loop through the array of MenuItems first before I can filter the array?

Here is my predicate:

NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"sItemName LIKE %@", searchText];

May I know how can I use this to filter the array of MenuItems that I have?

Thank you!

2

2 Answers

3
votes

What you need is a predicate like this:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"sItemName CONTAINS[cd] %@", searchText];

[cd] stands for case insensitiveness.

Alternately, if you like "LIKE", refer to this answer.

UPDATE:

You should also look at the data item you want to fetch - sItemName in your case. Through debugger, inspect what object does your data source array return? I am referring to the array you want to apply the above predicate to. Maybe there is some keypath hierarchy involved in getting through towards sItemName, in which case you need to use dot notation, such as Items.ItemLangs.sItemName.