我有一个看起来像
的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)"];
但表现非常缓慢。有没有办法让它更容易,更快?
答案 0 :(得分: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.schalter
和strasse.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"];