• 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: Core Data Predicate Builder - comparing dates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Data Predicate Builder - comparing dates


  • Subject: Re: Core Data Predicate Builder - comparing dates
  • From: Steve Cronin <email@hidden>
  • Date: Sat, 29 Aug 2009 23:45:42 -0500

Ben;

Thanks for taking the time to respond.
I believe that I was blinded by a build issue in my allegation that the Predicate Builder mechanism was not giving correct results.
This seems to be working fine now.


I'm glad you have expressed the fragility issue on equivalence - I'll remember that.

Thanks for the predicate in code.

It's amazing how often the Cocoa answers are simple and straightforward when you finally see them.
I might suggest the predicate you cited be considered for inclusion in the Apple documentation somewhere.
Most (all?) the examples use operators and some fixed value.
I know it may seem obvious (it does seem obvious now) but, when you don't know, a range of different examples can be a godsend...


Thank-you!
Steve

On Aug 29, 2009, at 7:35 PM, Ben Trumbull wrote:

I have a Core Data entity that has a dateCreated and a dateModified -
both NSDates in the object files.
I'd like to construct a predicate that will retrieve all records where
a record's dateModified is greater than that record's dateCreated.


Its deceptively easy to setup something that looks like it should work
using 'Control-click' and 'Key' in the predicate builder in XCode.
But when I run queries it doesn't appear to yield the right results.
My thinking is that the comparison operators don't properly evaluate
dates (am I wrong?)

Comparison operators work just fine on dates, although == and != are fragile since NSDates are double time stamps, and floating point numbers have odd == behavior.


What does the predicate look like ? How is it not working ? What does SQL logging show ?

So dropping back to code - how would I write this predicate in code?

[NSPredicate predicateWithFormat:@"dateModified > dateCreated"]

- Ben




_______________________________________________

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: 
 >re: Core Data Predicate Builder - comparing dates (From: Ben Trumbull <email@hidden>)

  • Prev by Date: Re: Get error message about registered observers when Object receives dealloc message
  • Next by Date: Re: How to extract the "Artist" information of an song file?
  • Previous by thread: re: Core Data Predicate Builder - comparing dates
  • Next by thread: core-data app design question
  • Index(es):
    • Date
    • Thread