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

Fetch with IB and programmatic predicates


  • Subject: Fetch with IB and programmatic predicates
  • From: Kevin Hoctor <email@hidden>
  • Date: Wed, 28 Feb 2007 15:48:55 -0600

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:


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

NSCompoundPredicate *predicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:greaterThanPredicate, lessThanPredicate, nil]];


// None of these do anything to filter the data
// [transactionController fetchWithRequest:<#(NSFetchRequest *) fetchRequest#> merge:<#(BOOL)merge#> error:<#(NSError * *)error#>
// [transactionController setFetchPredicate:predicate];
// [transactionController fetch:nil];
// [transactionTable needsDisplay];
}


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?

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: Re: Giving an Image a Reflective Surface
  • Next by Date: Re: Giving an Image a Reflective Surface
  • Previous by thread: Problems subclassing NSWindowController while keeping bindings working
  • Next by thread: NSNumberFormatter setExponentSymbol doing nothing (was Re: API to convert string to number?)
  • Index(es):
    • Date
    • Thread