• 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: NSPredicate Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPredicate Help


  • Subject: Re: NSPredicate Help
  • From: David Scheidt <email@hidden>
  • Date: Tue, 14 Apr 2009 12:29:15 -0400


On Apr 14, 2009, at 12:14 PM, Greg Robertson wrote:

I am using Core Data and have a two entity setup that in a simple form
could be modelled something like this:

Entity: Persons
- attribute: name
- attribute: birth
- relationship: cars (one to many with cars)

Entiry: Cars
- attribute: name

I would like to search for all persons not born on the date varDate
that have cars. I can do the search for all records/objects where the
date in the attribute birth is not equal to varDate, I can do this
with something like:
[request setPredicate:[NSPredicate predicateWithFormat:@"birth != %@",
self.varDate]];

but I am having difficulty figuring out how to write the predicate for
the relationship data, I would like something like:
[request setPredicate:[NSPredicate predicateWithFormat:@"cars != %@", NULL]];


Could someone help me write this predicate and show me the best way to
combine it with the first predicate?

I would do something like:

NSPredicate *birthPredicate = [NSPredicate predicateWithFormat:@"birth != %@", self.varDate]];
NSPredicate *carPredicate = [NSPredicate predicateWithFormat:@"cars.@count != 0"


NSPredicate *cp = [NSCompoundPredicate andPredicatewithSubpredicates: [NSArray arrayWithObjects:birthPredicate, carPredicate]];

[request setPredicate:cp];

I haven't actually checked that's quite right, but that's close.
_______________________________________________

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


References: 
 >NSPredicate Help (From: Greg Robertson <email@hidden>)

  • Prev by Date: Re: Best way to get a non-repeating random number?
  • Next by Date: Reading in dictionary from txt file: options for speed
  • Previous by thread: NSPredicate Help
  • Next by thread: Reading in dictionary from txt file: options for speed
  • Index(es):
    • Date
    • Thread