0

我有一个 NSPredicate 看起来像

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"((strasse.checks CONTAINS [cd] YES) AND (raumattribute.schalter CONTAINS[cd] YES)) OR ((strasse.standort.ortcheck CONTAINS [cd] YES) AND (raumattribute.schalter CONTAINS[cd] YES)) OR ((strasse.standort.ortcheck CONTAINS [cd] YES) AND(raumattribute.schalter CONTAINS[cd] NO) OR (strasse.checks CONTAINS [cd] YES) AND (raumattribute.schalter CONTAINS[cd] NO)) OR (strasse.standort.ortcheck CONTAINS [cd] NO)"];

但是性能非常非常慢。有没有办法让它更容易和更快?

4

1 回答 1

0

首先,您可以将谓词简化为如下所示:

NSPredicate *predicate =
[NSPredicate predicateWithFormat:
 @"(raumattribute.schalter CONTAINS YES OR raumattribute.schalter CONTAINS NO) AND \
 (strasse.checks CONTAINS YES OR strasse.standort.ortcheck CONTAINS YES) OR \
 strasse.standort.ortcheck CONTAINS NO"];

然后,如果我们假设raumattribute.schalterstrasse.standort.ortcheck只包含布尔值,我们可以再次简化谓词:

NSPredicate *predicate =
[NSPredicate predicateWithFormat:
 @"raumattribute.schalter.@count > 0 AND \
 (strasse.checks CONTAINS YES OR strasse.standort.ortcheck.@count > 0) OR \
 strasse.standort.ortcheck CONTAINS NO"];
于 2012-04-05T09:29:44.530 回答