• 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
CoreData Fetch Request Failing When Using NSDate in NSPredicate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CoreData Fetch Request Failing When Using NSDate in NSPredicate


  • Subject: CoreData Fetch Request Failing When Using NSDate in NSPredicate
  • From: David Garcea <email@hidden>
  • Date: Tue, 22 Nov 2005 15:46:04 -0500

I have a "Recently Added" smart playlist in my CoreData application. I create the predicate for the fetch request for this smart playlist using this code:

- (NSPredicate *)predicateWithDate30DaysAgoGreaterThanProperty: (NSString *)propertyName
{
// Get the current date.
NSDate *now = [NSDate date];


// Get the date 30 days prior to current date.
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:-30];
NSDate *date30DaysAgo = [calendar dateByAddingComponents:dateComps toDate:now options:0];
[dateComps release];


// Create the predicate.
NSPredicate *dateInLast30DaysPredicate = [NSPredicate predicateWithFormat:@"%@ > %@", propertyName, date30DaysAgo];


    return dateInLast30DaysPredicate;
}

When I print a description of this predicate to the console, I get something like this:
"dateAdded" > CAST(151788356.228000, "NSDate")


The problem is that the fetch request usually (but not always) fails, and this is the cause that gets logged to the console:

[NSCFDate length]: selector not recognized

Can anyone tell me what I am doing wrong?

Regards,
David

--
David Garcea
President/Founder
Trinfinity Software
http://www.TrinfinitySoftware.com
email@hidden


============================================= Creators of these popular shareware products:

Seagull Video Player
Make video playlists and play them full screen!
http://www.trinfinitysoftware.com/seagull.shtml

Time Track
Still keeping track of your time with a pencil and paper?
Let Time Track do it for you!
http://www.trinfinitysoftware.com/timetrack.shtml
=============================================



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: CoreData Fetch Request Failing When Using NSDate in NSPredicate
      • From: Diederik Hoogenboom <email@hidden>
    • Re: CoreData Fetch Request Failing When Using NSDate in NSPredicate
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: NSOpenPanel problem
  • Next by Date: [ANN] Lingon 1.0
  • Previous by thread: Re: NSFileManager -componentsToDisplayForPath:path
  • Next by thread: Re: CoreData Fetch Request Failing When Using NSDate in NSPredicate
  • Index(es):
    • Date
    • Thread