我对此感到难过:我已经在iPhone模拟器4.3和5.0中测试了我的应用程序的过滤功能,一切正常,但在iPhone上谓词给我错误的结果。 (我怀疑它与正则表达式有关,但我没有看到错误。)
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;
澄清:
entries
和keywords
是字典数组,但keywords
稍微复杂一些。重要的是entries
中的每个字典都包含一个名为meta
的字符串,它看起来像这样:“A,B,C,D”。如果用户搜索“C”,则正则表达式应该匹配。还有其他标准似乎不是问题,因为我检查了编译的谓词,看起来很好。meta LIKE[c] %@
)也给了我iPhone上的预期结果。A_ADD = addObject:
,D = objectForKey:
,A = objectAtIndex:
,A_NEW = arrayWithObjects:
,L = count
和S = stringByAppendingString:
。 (是的,我很懒:D)我在这里俯瞰什么?
答案 0 :(得分:1)
以下是其他人遇到类似问题的关键点:
NSPredicate
与iOS模拟器上的相应实现之间没有功能差异。