Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It would be better to see if suitsArray contains the string objectSuits, rather than using rangeOfString.</p> <pre><code>if ([suitsArray containsObject:objectSuits]); [resultObjectsArray addObject:object]; </code></pre> <p>After edit: I think I understand now. This method looks at each word in suitsArray, and if it finds any of them in objectSuits, then object is added to the resultObjectArray.</p> <pre><code> for (NSString *aWord in suitsArray) { if ([objectSuits rangeOfString:aWord].length == aWord.length) { [resultObjectArray addObject:objectSuits]; break; } } </code></pre> <p>Second Edit: After further thought, the above code has a flaw in the logic that may or may not be important -- because it uses rangeOfString it will find words inside other words. So, if objectSuits was "This wine goes well with cheesecake" and suitsArray contained the word cheese, it would find a match (I can't imagine a wine that would be good with cheese would be good with cheesecake). So, here is a better solution, I think, that breaks objectSuit up into individual words and puts them into a set. suitsArray is also converted to a set, so that we can use intersectsSet: to find if there are any common words.</p> <pre><code>NSCharacterSet *sepSet = [NSCharacterSet characterSetWithCharactersInString:@" ,.;"]; NSArray *words = [objectSuits componentsSeparatedByCharactersInSet:sepSet]; NSSet *objectSuitsWords = [NSSet setWithArray:words]; NSSet *suitsSet = [NSSet setWithArray:suitsArray]; BOOL ans = [suitsSet intersectsSet:objectSuitsWords]; </code></pre> <p>So, if ans is 1, then that object should be added to the results array. Notice that sepSet starts with a space and includes a comma, period, and semicolon. There might be other things you might want to include, but I think this should work in most cases.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload