• 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: Fetch with IB and programmatic predicates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fetch with IB and programmatic predicates


  • Subject: Re: Fetch with IB and programmatic predicates
  • From: Kevin Hoctor <email@hidden>
  • Date: Thu, 1 Mar 2007 15:24:08 -0600

On Feb 28, 2007, at 3:48 PM, Kevin Hoctor wrote:

I have a program patterned after the Core Data example CoreRecipes. I have a tree that imposes a predicate for a fetch using simple reference to a "transactions" set. The program also filters using a NSSearchField and that predicate combines nicely with the tree selection.

Now I want to add a date range to the predicate (for now I am simply using two NSDate entry fields on the window). How do I get the predicate from these two entries to affect the TransactionsArrayController? I have code to build a compound predicate, but I can't get it to affect the controller data:


[snip]

Do I override fetchWithRequest:merge:error: or some other action? If so, how do I do this without losing the clean predicate process that is working via IB?


Okay, I got the date predicate working by using a filter instead of a fetch, but each time I set a filter programatically, the NSSearchField stops filtering the list and is reset so none of the five methods are selected.


- (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];

[transactionController setFilterPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:greaterThanPredicate, lessThanPredicate, nil]]];
}


Is there a way to build this predicate in IB so I don't ever lose the two different filters and instead AND them? If that can't be done and I want to get the predicate from my NSSearchField (and keep that working as it was before the date fields were added), is there a way to do that in my program as opposed to IB?

Thanks,

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: How do I load my data on application startup
  • Next by Date: Re: NSViewAnimation and window destination alpha
  • Previous by thread: Re: How do I load my data on application startup
  • Next by thread: RE: How to capture my desktop?
  • Index(es):
    • Date
    • Thread