2012-04-04 163 views
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; 

對於澄清:

  • entrieskeywords是字典的數組,雖然keywords有點複雜。重要的是,entries中的每個字典都包含一個名爲meta的字符串,它可以看起來像這樣:「A,B,C,D」。如果用戶搜索「C」,那麼正則表達式應該匹配。還有其他的標準似乎不是問題,因爲我檢查了編譯後的謂詞,它看起來很好。
  • 我應該提一下,謂詞的第一部分(meta LIKE[c] %@)也給我iPhone上的預期結果。
  • 我在這裏有一些使用方便的宏:A_ADD = addObject:,D = objectForKey:,A = objectAtIndex:,A_NEW = arrayWithObjects:,L = countS = stringByAppendingString:。 (是的,我很懶:D)​​

我在這裏忽略了什麼?

+2

模擬器中的某些項目不區分大小寫。即「@ 2x」和「@ 2X」都將在模擬器中顯示視網膜圖像,但不是該設備。確保你傳遞的大寫字母是你期望的。 – jmstone617 2012-04-04 13:48:58

+0

感謝您的提示,這是很好的知道。但是,我仔細觀察了NSLog輸出,發現我的設備上的應用程序從過時的緩存文件中提取數據;我應該先刪除應用程序,而且謂詞可以正常工作。它可以是那麼容易... – vbwx 2012-04-04 17:03:19

+1

很高興你明白了。要麼提供答案,要麼標記這隻小狗關閉:) – jmstone617 2012-04-04 17:05:53

回答

1

以下是任何人的情況下的關鍵點別的有類似的問題:

  1. NSPredicate之間在iPhone和在iOS模擬器相應的執行沒有功能上的差別。
  2. 如果您的應用在實際設備上的表現與模擬器上的行爲不同,請仔細檢查文件名和其他字符串是否需要大小寫,如jmstone表示。
  3. 如果問題仍然存在,請從模擬器和設備中刪除應用程序。 Xcode有許多自動行爲,但它不會清理模擬器或設備上的任何內容。
相關問題