0
votes

I am trying to fetch an entity from coredata using NSPredicate. I am trying to do a 'search as you type' approach. It works fine on a simple product name like "chair" or "Table".

But as soon as I tried the more complicate stuff like "Wheelchair - electric - power" then when I type in "Wheelchair electric" the result is not showing. I think it has to do with my NSPredicate predicateWithFormat but I've been at this for awhile now. So I need some help.

Here is my code (these are my best guesses)

    request.predicate = [NSPredicate predicateWithFormat:@" Name BEGINSWITH [c] %@ ",searchText];
    request.predicate = [NSPredicate predicateWithFormat:@" Name BEGINSWITH [c] %@ OR Name like[cd] %@ ",searchText,searchText];  

Thanks in advance :) Pondd

1

1 Answers

1
votes

To have an OR search you will have to first split the search term by whitespace into an array. Then you need to create a LIKE predicate for each individual component. Finally you have to combine the individual predicates with several OR compound predicates.