Re: NSPredicateEditor and aggregate operations
Re: NSPredicateEditor and aggregate operations
- Subject: Re: NSPredicateEditor and aggregate operations
- From: Tom <email@hidden>
- Date: Wed, 17 Dec 2008 14:21:33 +1000
I've got around it by implementing a kind of "man in the middle"
subclass of NSPredicateEditorRowTemplate. I set the class of the row
template to my subclass in IB and it automatically adds the "ANY"
modifier to whatever is already configured. It removes the "ANY"
modifier from the predicate before calling superclass function, and
puts it back on the return values of super class functions. I've
included the overridden functions below.
It would be much easier if there was an option called "Predicate
Modifier" in IB for row templates.
-(NSComparisonPredicate*)copyPredicate:
(NSComparisonPredicate*)aPredicate andChangeModifierTo:
(NSComparisonPredicateModifier)aMod
{
NSComparisonPredicate* aCopy = nil;
aCopy = (NSComparisonPredicate*)[NSComparisonPredicate
predicateWithLeftExpression:[aPredicate leftExpression]
rightExpression:[aPredicate rightExpression]
modifier:aMod
type:[aPredicate predicateOperatorType]
options:[aPredicate options]];
return aCopy;
}
- (double)matchForPredicate:(NSPredicate *)predicate
{
//if the modifier is "ANY", then strip it off and pass it to super
if([predicate isKindOfClass:[NSComparisonPredicate class]]){
NSComparisonPredicate* p = (NSComparisonPredicate*)predicate;
if([p comparisonPredicateModifier] == NSAnyPredicateModifier){
return [super matchForPredicate:[self copyPredicate:p
andChangeModifierTo:NSDirectPredicateModifier]];
}
}
//else, don't handle it
return 0.0;
}
- (void)setPredicate:(NSPredicate *)predicate
{
//strip off "ANY" modifier and pass it to super
NSComparisonPredicate* p = (NSComparisonPredicate*)predicate;
[super setPredicate:[self copyPredicate:p
andChangeModifierTo:NSDirectPredicateModifier]];
}
- (NSPredicate *)predicateWithSubpredicates:(NSArray *)subpredicates
{
//add the "ANY" modifier back onto the predicate
NSComparisonPredicate* ret = (NSComparisonPredicate*)[super
predicateWithSubpredicates:subpredicates];
return [self copyPredicate:ret
andChangeModifierTo:NSAnyPredicateModifier];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden