Reputation: 388
I am stumped by this: I've tested the filter function of my app in the iPhone Simulator 4.3 and 5.0 and everything works, but on the iPhone the predicate gets me the wrong results. (I suspect it has something to do with the regex, but I don't see an error.)
if (!selectionDidChange)
return;
[matches release];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"meta LIKE[c] %@",
UniversalKeyword];
NSPredicate *regional = [NSPredicate predicateWithFormat:@"regional == NIL OR regional == NO OR "
@"(regional == YES AND title.%K != NIL)", CurrentLanguage];
NSPredicate *exclusive = (exclusiveUpgrade ? [NSPredicate predicateWithValue:YES] :
[NSPredicate predicateWithFormat:@"exclusive == NIL OR exclusive == NO"]);
NSMutableArray *predicates = [[[NSMutableArray alloc] initWithCapacity:5] autorelease];
for (int i = 0; i < L(keywords); i++)
{
int selection = [D(A(keywords, i), @"selection") intValue];
if (selection >= 0)
A_ADD(predicates, ([NSPredicate predicateWithFormat:@"meta MATCHES[c] %@",
S(S(@".*\\b", D(A(D(A(keywords, i), @"values"), selection), @"name")), @"\\b.*")]));
}
NSPredicate *compound = [NSCompoundPredicate andPredicateWithSubpredicates:predicates];
[predicates removeAllObjects];
[predicates addObject:predicate];
[predicates addObject:compound];
predicate = [NSCompoundPredicate andPredicateWithSubpredicates:A_NEW(regional, exclusive,
[NSCompoundPredicate orPredicateWithSubpredicates:predicates])];
matches = [[entries filteredArrayUsingPredicate:predicate] retain];
selectionDidChange = NO;
For clarification:
entries
and keywords
are arrays of dictionaries, although keywords
is a bit more complex. Important is that each dictionary in entries
contains a string named meta
that can look something like this: "A, B, C, D". And if the user searches for "C", the regex should match. There are other criteria that don't seem to be the problem, since I checked the compiled predicate and it looks fine.meta LIKE[c] %@
) gives me the expected result on the iPhone as well.A_ADD = addObject:
, D = objectForKey:
, A = objectAtIndex:
, A_NEW = arrayWithObjects:
, L = count
and S = stringByAppendingString:
. (Yeah, I'm lazy :D )What am I overlooking here?
Upvotes: 0
Views: 970
Reputation: 388
Here are the key points in case anybody else has a similar problem:
NSPredicate
on the iPhone and the corresponding implementation on the iOS Simulator.Upvotes: 1