代码在模拟器上工作,但不在iPhone上?

时间:2012-04-04 13:17:20

标签: iphone ios cocoa-touch

我对此感到难过:我已经在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;

澄清:

  • 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)​​

我在这里俯瞰什么?

1 个答案:

答案 0 :(得分:1)

以下是其他人遇到类似问题的关键点:

  1. iPhone上的NSPredicate与iOS模拟器上的相应实现之间没有功能差异。
  2. 如果您的应用在实际设备上的行为与在模拟器上的行为不同,请仔细检查文件名和其他字符串以进行大小写,例如 jmstone 表示。
  3. 如果问题仍然存在,请从模拟器和设备中删除该应用。 Xcode有许多自动行为,但它不会清除模拟器或设备上的任何内容。
相关问题