NSPredicate to select keywords that are in the line

In the master data, I have an object called a keyword with property text. I want to find all the keyword objects that are contained in a particular ad.

I tried:

[NSPredicate predicateWithFormat:@"%@ contains[c] text", myString]; 

But this is a failure. It seems that if it works, only if it changes.

+4
source share
2 answers

A predicate works on an entity, so you have a predicate. Since your text property of the object contains one word, you would split the string into several words and then test:

 // This is very simple and only meant to illustrate the property, you should // use a proper regex to divide your string and you should probably then fold // and denormalize the components, etc. NSSet* wordsInString = [NSSet setWithArray:[myString componentsSeparatedByString:@" "]]; NSPredicate* pred = [NSPredicate predicateWithFormat:@"SELF.text IN %@", wordsInString]; 
+3
source

I think you are doing the opposite.

Try it.

 [NSPredicate predicateWithFormat:@"text contains[cd] %@", myString]; 
0
source

Source: https://habr.com/ru/post/1336275/


All Articles