• 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
Core Data: combining IB & code-based filter predicates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Core Data: combining IB & code-based filter predicates


  • Subject: Core Data: combining IB & code-based filter predicates
  • From: Kevin Hoctor <email@hidden>
  • Date: Mon, 5 Mar 2007 16:01:17 -0600

I have a Core Data document app and I need it to work with two or more filters based on user input. There's the standard NSSearchField in IB that works fine and I can also capture a user-selected date and set that filter predicate for my data:

// This routine lets me capture the current filter (initially from the NSSearchField)

- (NSPredicate *)filterPredicate
{
	return [transactionController filterPredicate];
}

// This routine replaces the filter set by the NSSearchField; I need a way to capture and combine them

- (void)refreshDatePredicate
{
NSExpression *lhs = [NSExpression expressionForKeyPath:@"date"];

NSExpression *greaterThanRhs = [NSExpression expressionForConstantValue:[fromDate dateValue]];
NSPredicate *greaterThanPredicate = [NSComparisonPredicate predicateWithLeftExpression:lhs rightExpression:greaterThanRhs modifier:NSDirectPredicateModifier type:NSGreaterThanOrEqualToPredicateOperatorType options:0];

NSExpression *lessThanRhs = [NSExpression expressionForConstantValue: [toDate dateValue]];
NSPredicate *lessThanPredicate = [NSComparisonPredicate predicateWithLeftExpression:lhs rightExpression:lessThanRhs modifier:NSDirectPredicateModifier type:NSLessThanOrEqualToPredicateOperatorType options:0];

NSPredicate *datePredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:greaterThanPredicate, lessThanPredicate, nil]];
[transactionController setFilterPredicate:datePredicate];
}


The problem is that only one of these is active at one time. I need to know the best way to combine these filters. I'd love to do it all in IB, but I don't think I can capture the date range information and combine it there so I'm happy to do it in the code. What's the best practice method for doing complex filter predicates based on various user selections?

I'm really stuck behind a mental roadblock on this one so any help is much appreciated! Thanks.

Peace,

Kevin Hoctor
email@hidden
No Thirst Software LLC
http://nothirst.com


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: [Moderator] EOT Re: Interesting private API
  • Next by Date: [MEET] March CocoaHeads Meetings
  • Previous by thread: Re: Multiple QTMovies and Images under one controller
  • Next by thread: Re: Core Data: combining IB & code-based filter predicates
  • Index(es):
    • Date
    • Thread