• 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: predicate with NSDates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: predicate with NSDates


  • Subject: Re: predicate with NSDates
  • From: Andres <email@hidden>
  • Date: Fri, 19 Oct 2007 23:17:39 -0400

My Employee entity has a too many relationship called "myVacations"  to a

Vacation entity which has date attributes "startDate" and "endDate". I want

to find out which employees are on vacation on a specific NSDate. I am

having trouble with the predicate below. What's the correct predicate

format?


 NSDate *today = [NSDate date];

 NSEntityDescription *entityDescription = [NSEntityDescription

entityForName:  @"Employee"  inManagedObjectContext: managedObjectContext];

 NSFetchRequest *request = [[NSFetchRequest alloc] init];


 [request setEntity: entityDescription];


 NSPredicate *predicate = [NSPredicate predicateWithFormat:  @"(

myVacations.startDate < %@) AND ( myVacations.endDate > %@) ",  today,

today];

 [request setPredicate: predicate];


 NSError *error =  nil ;

 NSArray *employeesOnVacationToday = [managedObjectContext

executeFetchRequest:

request error: &error];


I get the following error:

 -[NSCFArray compare:]: selector not recognized [self = 0x3d3690]




After reading here,

http://developer.apple.com/documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html

I learned I should use the ANY operator when referring to a to-many
relationship in a predicate format so I now have the following predicate and
I no longer get the "selector not recognized" run time error. I also
realized what I wanted is employees who are NOT on vacation on a specific
day so I changed the logic to reflect that. However, when I use the
predicate below in a fetch request I get an empty array. Some employees
don't have any vacation days set so I added the check to match myVacations
== nil but I still get an array with count of 0.
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"((ANY
myVacations == nil) OR ((ANY myVacations.startDate > %@) OR (ANY
myVacations.endDate < %@)))", day, day];


Does this predicate format describe the Employees I'm looking for? I would
appreciate any help. Thanks.


Andres
_______________________________________________

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: How to make NSComboBox work in fullscreen mode
  • Next by Date: Re: Mulit-state buttons
  • Previous by thread: predicate with NSDates
  • Next by thread: NSLocalizedString and plural forms
  • Index(es):
    • Date
    • Thread