Friday, 27 September 2013

In Core Data, should I put the more restrictive or less restrictive predicate first?

In Core Data, should I put the more restrictive or less restrictive
predicate first?

-(NSPredicate *) predicateForExactMatch
{
enum typeOfAutocompleteNew toc = [[self class] typeOfAutoComplete];
NSPredicate * predictNameMatch=[NSPredicate
predicateWithFormat:@"%K==[cd]%@",NSStringFromSelector(@selector(strNameofPlace)),self.strCurrentKeyword];
NSPredicate * entryTypeNameMatch=[NSPredicate
predicateWithFormat:@"%K==[cd]%@",NSStringFromSelector(@selector(strEntry)),@(toc)];
NSPredicate * final = [NSCompoundPredicate
andPredicateWithSubpredicates:@[predictNameMatch,entryTypeNameMatch]];
return final;
}
Which one is better?
NSPredicate * final = [NSCompoundPredicate
andPredicateWithSubpredicates:@[predictNameMatch,entryTypeNameMatch]];
or
NSPredicate * final = [NSCompoundPredicate
andPredicateWithSubpredicates:@[entryTypeNameMatch,predictNameMatch]];
Here, predictNameMatch is definitely far more restrictive. At most 1-2 are
exact match. entryTypeNameMatch match like 25% of data.

No comments:

Post a Comment