• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPredicateEditor and aggregate operations
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: nib loading / displaying question.
  • Next by Date: RE: nib loading / displaying question.
  • Previous by thread: NSPredicateEditor and aggregate operations
  • Next by thread: Thread ID in crash log
  • Index(es):
    • Date
    • Thread