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