1
數組中的子選項用於初始化NSCompoundPredicate影響效率嗎?NSCompoundPredicate subpredicate order
實施例:
NSString * str = [self getAStr];
NSManagedObject * mo = [self getAMo];
NSString * fmt = @"(stringAttribute ==[cd] %@) AND (relationships CONTAINS %@)";
NSString * fmt2 = @"[email protected] != 0";
NSPredicate * p1 = [NSPredicate predicateWithFormat:fmt,str,mo];//expensive predicate
NSPredicate * p2 = [NSPredicate predicateWithFormat:fmt2,nil];//less expensive predicate
NSCompoundPredicate * cp = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1,p2];
[self fetchSomethingWithPredicate:cp];
在上面的例子中並p1和p2變化的順序如何化合物謂詞進行求值?顯然首先評估p2會更有效率,假設p2將被忽略,如果p2評估爲false。