0
我被这个难住了:我测试了我的应用程序在iPhone模拟器4.3和5.0中的过滤功能,一切正常,但在iPhone上,谓词让我错误的结果。 (我怀疑它是与正则表达式,但我没有看到一个错误。)在模拟器上工作的代码,但不在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)
我在这里忽略了什么?
模拟器中的某些项目不区分大小写。即“@ 2x”和“@ 2X”都将在模拟器中显示视网膜图像,但不是该设备。确保你传递的大写字母是你期望的。 – jmstone617 2012-04-04 13:48:58
感谢您的提示,这是很好的知道。但是,我仔细观察了NSLog输出,发现我的设备上的应用程序从过时的缓存文件中提取数据;我应该先删除应用程序,而且谓词可以正常工作。它可以是那么容易... – vbwx 2012-04-04 17:03:19
很高兴你明白了。要么提供答案,要么标记这只小狗关闭:) – jmstone617 2012-04-04 17:05:53